Tree Cutting Game
Time limit1sMemory limit1024 MB
Given a tree with 2^K-1 vertices, find the maximum of (vertices minus edges) GS can reach by removing vertices and re-joining components.
Problem
GS and CU play a tree cutting game on an acyclic undirected graph with vertices and edges. First, GS may repeat either of the following two actions as many times as desired.
remove v: Choose a vertex in , remove it, and remove all edges connected to .join u v: Choose two vertices and that belong to different components of , and add an edge between them.
After GS finishes, CU may repeat either of the following two actions as many times as desired.
join u v: Choose two vertices and that belong to different components of , and add an edge between them.slide u v w: When both the edge - and the edge - exist in , remove the edge - and add the edge -.
When CU finishes, CU wins if has two components with exactly the same shape. Otherwise, GS wins.
GS learned that removing all vertices wins easily. So GS decided to win by maximizing the value of (number of vertices) - (number of edges) in after GS finishes. Help GS plan a strategy.
Input
The first line contains the number of vertices and the number of edges of .
Each of the next lines contains two vertices and that are connected by an edge of , separated by a space.
Output
Print the value of (number of vertices) - (number of edges) in after GS finishes, using the strategy GS chose.
Constraints
- (= 131071)
- is guaranteed to satisfy for some integer .
- ,
Hint
Two graphs and have exactly the same shape if you can number the vertices of and so that the sets of number pairs connected by edges are the same in both graphs.