Walks and Queries
Time limit3sMemory limit1024 MB
After each path is added, count the rooms whose connected component contains an odd cycle, since those rooms can walk every long enough length.
- Level
Medium6 of 10
- Topics
- Union-find, Graph
- Solved
- No attempts yet
Problem
Seongseo picked candidate places near Soongsil University for a room search and numbered them from to . Each place has exactly one room. Many factors matter when choosing a room, but Seongseo values freedom to walk above all else.
Path connects two different places and . Walking from to takes unit of time, and walking from to also takes unit of time. Once you start walking, you cannot turn or stop midway. You must walk for exactly unit of time and arrive at the other end.
Walk starts at some place , follows paths, and finally returns to . A walk may visit the same place or path many times, but you cannot pause for even a moment.
Seongseo looks around the places and adds paths with a nice atmosphere to a personal path list. A satisfying walk uses only the paths on that list.
Seongseo wants to walk for a long time and return at a chosen moment. Room has high walking freedom if, for every integer of at least , there is a satisfying walk that starts at and takes exactly units of time.
The path list starts empty. Each time Seongseo finds a good path, the path is added to the list. After each change, find how many rooms have high walking freedom.
Specifically, you must process queries of the following form.
a b: Add path to the path list. Then print the number of rooms with high walking freedom.

For example, suppose there are rooms and the path list is . The figure above shows this case.
Room has no satisfying walk that takes units of time, so its walking freedom is not high.
Rooms and have satisfying walks that take or units of time, but none that take or units of time. Their walking freedom is not high.
Rooms , , and have satisfying walks for , , , , and so on. Their walking freedom is high.
So in this figure, the number of rooms with high walking freedom is .
Input
The first line contains and , the number of places and the number of queries, separated by a space.
Each of the next lines contains and , the two places connected by the path added in the -th query, separated by a space.
Output
For each query, print the answer on its own line.
Constraints
- No query is given more than once.
- All given numbers are integers.
Hint
The input and output are large, so use the fast I/O method described in the language guide on pages 2 to 4 of the problem booklet.