#D6139. Islands Survival
Islands Survival
Islands Survival
problem
There is a simple concatenated undirected graph with vertices and edges. The vertices are numbered . The edges are numbered , and the edge connects the vertices and . Also, the edge disappears at time . It takes a unit time to pass through each side. You are initially at vertex 1 at time 0. You want to maximize the score you get by time by acting optimally. The score is initially 0 and the event occurs according to:
- If the current time satisfies , it ends. If not, go to 2.
- All edges with disappear.
- If the vertex you are in is and the number of vertices contained in the connected component including the vertex is , will be added to the score.
- You either move to one of the vertices and adjacent to it, or stay at vertex . However, in the former case, the edge that has already disappeared cannot be used.
- As , go to 1.
Find the maximum score you can get.
output
Output the maximum score. Also, output a line break at the end.
Example
Input
5 4 2 1 2 2 2 3 1 1 4 2 4 5 1
Output
8
inputFormat
outputFormat
output
Output the maximum score. Also, output a line break at the end.
Example
Input
5 4 2 1 2 2 2 3 1 1 4 2 4 5 1
Output
8
样例
5 4 2
1 2 2
2 3 1
1 4 2
4 5 1
8