This page is still under construction.

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

Godzilla

Time limit1sMemory limit128 MB

Summary
Each day Godzilla starts at junction 1, walks a path, eats a building and destroys buildings on the way; each night one person leaves every standing building. Maximize the total eaten.
Level

Hard8 of 10

Topics
Graph, Greedy, Implementation, Math
Solved
No attempts yet

Problem

The dreaded monster Godzilla has decided to visit Byteburg again. Every day the monster crawls out of the ocean, reaches one of the city's skyscrapers, and eats it together with everyone living inside. Eating one skyscraper takes Godzilla an entire day; afterwards it slips back into the sea. While moving across the city, Godzilla's tail accidentally destroys every skyscraper it passes along the way.

The citizens of Byteburg can hardly stand this. That is why, every night, one citizen flees to the countryside from each skyscraper that is still standing.

Every junction in Byteburg holds exactly one skyscraper, and the junctions are joined by two-way streets. One junction sits right next to the ocean; this is where Godzilla begins its journey each day. Godzilla always travels along streets.

Godzilla must hurry, choosing both the skyscrapers to eat and the streets to travel with great care. It cannot eat a skyscraper that has already been eaten or destroyed along the way. What is the maximum number of people Godzilla can eat before the city becomes completely deserted?

Input

The first line contains two integers nn and mm (1≤n≤100 0001 \le n \le 100\,000, 0≤m≤500 0000 \le m \le 500\,000), the number of junctions and the number of streets. The junctions are numbered 11 through nn, and junction 11 is the one next to the ocean. The second line contains nn integers kik_i (0≤ki≤100 0000 \le k_i \le 100\,000), where kik_i is the number of people living in the skyscraper at junction ii. Each of the next mm lines contains two integers aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i), meaning there is a street connecting junctions aia_i and bib_i. Every junction is reachable from junction 11.

Output

Print, on a single line, the number of people Godzilla eats when it chooses which skyscrapers to eat and how to move optimally.

Examples2

  1. Example 1

    Input
    5 5
    1 3 2 4 7
    1 2
    1 3
    2 3
    2 4
    3 5
    
    Expected output
    11
    
  2. Example 2

    Input
    5 4
    5 4 3 2 1
    1 2
    1 3
    1 4
    1 5
    
    Expected output
    9