This page is still under construction.

Parts of this page are still being built. What you see may change.

Conquest

Time limit4sMemory limit1024 MB

Summary
Starting from island 1, absorb adjacent islands with strictly smaller armies, merging their sizes; maximize the final total army.
Level

Medium7 of 10

Topics
Graph, Greedy, Heap, Union-find
Solved
No attempts yet

Problem

Nomads, Kingdoms, and Tribes live 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 on, the Spanning Nation can attack any island that is directly connected to some island already conquered by the Spanning Nation. Wars are resolved without any fighting. The Spanning Nation only attacks an island if that island's army is strictly smaller than the Spanning Nation's army. The smaller island army simply concedes and joins 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.

Input

The first line contains the integer NN (1≤N≤200 0001 \leq N \leq 200\,000), the number of islands, and MM (0≤M≤200 0000 \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 (1≤u,v≤N1 \leq u, v \leq N), indicating that there is a bridge between islands uu and vv. There is at most one bridge between any pair of islands.

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

Output

Display the maximum possible army size of the Spanning Nation.

Examples2

  1. Example 1

    Input
    6 5
    1 4
    3 4
    2 4
    6 3
    5 4
    2
    4
    1
    0
    10
    2
    
    Expected output
    9
    
  2. Example 2

    Input
    6 5
    3 4
    3 1
    2 3
    6 1
    5 3
    2
    3
    0
    1
    3
    3
    
    Expected output
    3