문제
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 , the cows at positions and swap. In minute , 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.
입력
The first line contains integers and . Each of the next lines contains ().
출력
Print lines of output, where the th line contains the number of unique positions that cow reaches.
예제 입력 1
5 4
1 3
1 2
2 3
2 4
예제 출력 1
4
4
3
4
1
점수
Test cases 1-5 satisfy .Test cases 6-10 satisfy .Test cases 11-20 satisfy no additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인