#5121. Problem 3. Dance Mooves
Problem 3. Dance Mooves
Problem 3. Dance Mooves
USACO 2021 January Contest, Gold
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.
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:
6 4 7 1 2 2 3 3 4 4 5
SAMPLE OUTPUT:
5 4 3 3 3 1
After minutes, the cows in increasing order of position are .
- Cow reaches positions .
- Cow reaches positions .
- Cow reaches positions .
- Cow reaches positions .
- Cow reaches positions .
- Cow never moves, so she never leaves position .
SCORING: Test cases 1-5 satisfy .Test cases 6-10 satisfy .Test cases 11-20 satisfy no additional constraints.
Problem credits: Chris Zhang