Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N = int(input())
- result = list(map(int, input().split()))
- K = int(input())
- dict_result = {}
- cabel = []
- summ = 0
- for i in range(1,N+1):
- dict_result.update({i:set()})
- for i in range(K):
- number = list(map(int, input().split()))
- cabel.append(number)
- dict_result[number[0]].add(number[1])
- dict_result[number[0]].add(number[0])
- dict_result[number[1]].add(number[0])
- dict_result[number[1]].add(number[1])
- set_cabel = set()
- for i in dict_result.values():
- if i != set():
- i = frozenset(i)
- set_cabel.add(i)
- for i in set_cabel:
- minimum = 1000000
- for j in i:
- if result[j-1] < minimum:
- minimum = result[j-1]
- poz = j-1
- summ += result[poz]
- result[poz] = 0
- for j in cabel:
- if j[0] in i:
- if result[j[0]-1] >= result[j[1]-1]:
- if result[j[0]-1] > j[2]:
- result[j[0] - 1] = j[2]
- else:
- if result[j[1]-1] > j[2]:
- result[j[1] - 1] = j[2]
- print(sum(result)+summ)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement