PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000472. Xóa đỉnh (Erasing Vertices 2)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xóa đỉnh (Erasing Vertices 2)

Erasing Vertices 2

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A simple undirected graph has positive vertex values AiA_i. Delete one remaining vertex and its incident edges at each step. The cost is the sum of values of its remaining neighbors before deletion. Remove all vertices, minimizing the largest step cost.

Input

Read N,MN,M, the NN values AiA_i, then MM pairs Ui,ViU_i,V_i.

Output

Print the minimum possible maximum cost.

Subtasks

Subtask 1 (20 points)

  • 1≤N≤121\le N\le12, 0≤M≤660\le M\le66
  • 1≤Ai≤1091\le A_i\le10^9, 1≤Ui,Vi≤N1\le U_i,V_i\le N, Ui≠ViU_i\ne V_i; no parallel edges; all data are integers.

Subtask 2 (30 points)

  • 1≤N≤20001\le N\le2000, 0≤M≤50000\le M\le5000
  • 1≤Ai≤1091\le A_i\le10^9, 1≤Ui,Vi≤N1\le U_i,V_i\le N, Ui≠ViU_i\ne V_i; no parallel edges; all data are integers.

Subtask 3 (50 points)

  • 1≤N≤2⋅1051\le N\le2\cdot10^5, 0≤M≤2⋅1050\le M\le2\cdot10^5
  • 1≤Ai≤1091\le A_i\le10^9, 1≤Ui,Vi≤N1\le U_i,V_i\le N, Ui≠ViU_i\ne V_i; no parallel edges; all data are integers.

Examples

Example 1

Input

4 3
3 1 4 2
1 2
1 3
4 1

Output

3

Explanation

Delete 3, 1, 2, 4 with costs 3, 3, 0, 0. Every initial cost is at least 3.

Example 2

Input

7 13
464 661 847 514 74 200 188
5 1
7 1
5 7
4 1
4 5
2 4
5 2
1 3
1 6
3 5
1 2
4 6
2 7

Output

1199

Explanation

The threshold 1199 permits all vertices to be removed; threshold 1198 does not.