Dance Mooves
시간 제한: 1000ms메모리 제한: 512MB출처: USACO 2021 January SilverBOJ 20970
문제
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
출력
4 4 3 4 1
코드를 제출하려면 로그인하세요.