while True:
    try:
        n = int(input())
        red_list = list(map(int, input().split()))
        blue_list = []
        for i in range(n):
            blue_list.append(list(map(int, input().split())))
        # print(red_list)
        # print(blue_list)

        pay = red_list[:]
        for j in range(n):
            blue1 = blue_list[j][0] - 1
            blue2 = blue_list[j][1] - 1
            # print(blue1, blue2)
            if red_list[blue1] + red_list[blue2] < red_list[j]:
                # 替换掉花费较高的红药剂,使用两种较便宜的蓝药剂替代
                pay[j] = red_list[blue1] + red_list[blue2]
        print(sum(pay))

    except Exception as e:
        break