PivotOJ

Conquest

시간 제한: 4000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2020BOJ 21202

문제

Nomads, Kingdoms, and Tribes are on the islands of the great seas. Bridges span between islands allowing travel between them. It is possible to get from every island to every other island through some sequence of bridges. The islands were at peace until everything changed when the Spanning Nation attacked!

Initially the Spanning Nation occupies island 1.  From that point forward, the Spanning Nation can attack any island that is directly connected to some island already conquered by the Spanning Nation.  Thankfully wars are resolved without any fighting. The Spanning Nation only attacks an island if the island's army is strictly smaller than the Spanning Nation's army.  The smaller island army will simply concede and join the Spanning Nation's army.

As the tactical advisor of the Spanning Nation, determine the maximum possible army size the Spanning Nation can have after making a series of attacks.

입력

The first line contains the integer NN (1N2000001 \leq N \leq 200\,000), which is the number of islands, and MM (0M2000000 \leq M \leq 200\,000), the number of bridges.

The next MM lines describe the bridges. Each of these lines contains two distinct integers uu and vv (1u,vN1 \leq u, v \leq N), indicating that there is a bridge between the islands uu and vv.  There is at most one bridge between any pair of islands.

The next NN lines describe the islands' army size in order. Each of these lines contains a single integer ss (0s10000 \leq s \leq 1\,000), which is the army size of this island.

출력

Display the maximum possible army size of the Spanning Nation.

예제

예제 1

입력
6 5
1 4
3 4
2 4
6 3
5 4
2
4
1
0
10
2
출력
9

예제 2

입력
6 5
3 4
3 1
2 3
6 1
5 3
2
3
0
1
3
3
출력
3
코드를 제출하려면 로그인하세요.