atcoder#ABC267E. [ABC267E] Erasing Vertices 2

[ABC267E] Erasing Vertices 2

Score : 500500 points

Problem Statement

You are given a simple undirected graph with NN vertices and MM edges. The ii-th edge connects Vertices UiU_i and ViV_i. Vertex ii has a positive integer AiA_i written on it.

You will repeat the following operation NN times.

  • Choose a Vertex xx that is not removed yet, and remove Vertex xx and all edges incident to Vertex xx. The cost of this operation is the sum of the integers written on the vertices directly connected by an edge with Vertex xx that are not removed yet.

We define the cost of the entire NN operations as the maximum of the costs of the individual operations. Find the minimum possible cost of the entire operations.

Constraints

  • 1N2×1051 \le N \le 2 \times 10^5
  • 0M2×1050 \le M \le 2 \times 10^5
  • 1Ai1091 \le A_i \le 10^9
  • 1Ui,ViN1 \le U_i,V_i \le N
  • The given graph is simple.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \dots ANA_N

U1U_1 V1V_1

U2U_2 V2V_2

\vdots

UMU_M VMV_M

Output

Print the answer.

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

By performing the operations as follows, the maximum of the costs of the NN operations can be 33.

  • Choose Vertex 33. The cost is A1=3A_1=3.
  • Choose Vertex 11. The cost is A2+A4=3A_2+A_4=3.
  • Choose Vertex 22. The cost is 00.
  • Choose Vertex 44. The cost is 00.

The maximum of the costs of the NN operations cannot be 22 or less, so the solution is 33.

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
1199