#USACO2327. 舞步
舞步
Farmer John’s cows are showing off their new dance mooves!At first, all cows stand in a line with cow in the th position in line. The sequence of dance mooves is given by pairs of positions . In each minute of the dance, the cows in positions and in line swap. The same swaps happen again in minutes , again in minutes, and so on, continuing indefinitely in a cyclic fashion. In other words,
- In minute 1, the cows at positions and swap.
- In minute 2, the cows at positions and swap.
- ...
- In minute , the cows in positions and swap.
- In minute , the cows in positions and swap.
- In minute , the cows in positions and swap.
- and so on ...
For each cow, please determine the number of unique positions in the line she will ever occupy.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains integers and . Each of the next lines contains .
OUTPUT FORMAT (print output to the terminal / stdout):
Print lines of output, where the th line contains the number of unique positions that cow reaches.
SAMPLE INPUT:
5 4
1 3
1 2
2 3
2 4
SAMPLE OUTPUT:
4
4
3
4
1
- Cow 1 reaches positions {1,2,3,4}.
- Cow 2 reaches positions {1,2,3,4}.
- Cow 3 reaches positions {1,2,3}.
- Cow 4 reaches positions {1,2,3,4}.
- Cow 5 never moves, so she never leaves position 5.
SCORING:
- Test cases 1-5 satisfy N≤100,K≤200.
- Test cases 6-10 satisfy N≤2000,K≤4000.
- Test cases 11-20 satisfy no additional constraints.