문제
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 in a cyclic fashion for a total of minutes (). 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.
Note: the time limit per test case on this problem is twice the default.
입력
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
6 4 7
1 2
2 3
3 4
4 5
예제 출력 1
5
4
3
3
3
1
점수
Test cases 1-5 satisfy .Test cases 6-10 satisfy .Test cases 11-20 satisfy no additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인