Escape
Time limit2sMemory limit512 MB
Starting at vertex 1 in a connected undirected graph, walk without immediately reusing the edge you just came from, collecting each vertex's value the first time you visit it, and maximize the total.
- Level
Hard8 of 10
- Topics
- Graph, DFS, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
You are given an undirected graph whose vertices carry positive values. The vertices are numbered from 1 to , and the -th vertex has value . You start at vertex 1 and may move around the graph under the constraint that you cannot traverse the edge you just came from. At each vertex, you gain points equal to that vertex's value, but only the first time you visit it.
Find the maximum total number of points you can obtain.
Input
The input is given from standard input in the following format.
The first line contains the number of vertices and the number of edges of the graph. The second line contains the value of each vertex. The following lines each contain the numbers of the two vertices connected by an edge.
Output
Output the answer on one line.
Constraints
- There are no multiple edges or self-loops
- The graph is connected