#P7298. [USACO21JAN] Dance Mooves G
[USACO21JAN] Dance Mooves G
Problem Description
Farmer John's cows are showing off their newest dance moves.
At the beginning, all cows () stand in a line, and cow is in position . A dance move sequence is given as () pairs of positions . During minute of the dance, the cows in positions and swap positions. The same swaps happen again during minutes , again during minutes , and so on, repeating periodically for a total of minutes (). In other words:
- In minute , the cows in positions and swap positions.
- In minute , the cows in positions and swap positions.
- In minute , the cows in positions and swap positions.
- In minute , the cows in positions and swap positions.
- In minute , the cows in positions and swap positions.
- And so on.
For each cow, find how many distinct positions she will occupy in the line.
Note: For this problem, the time limit for each test case is twice the default time limit.
Input Format
The first line contains , , and . The next lines each contain ().
Output Format
Output lines. Line should contain the number of distinct positions that cow can reach.
6 4 7
1 2
2 3
3 4
4 5
5
4
3
3
3
1
Hint
After minutes, the cows in each position are .
- Cow can reach positions .
- Cow can reach positions .
- Cow can reach positions .
- Cow can reach positions .
- Cow can reach positions .
- Cow never moved, so she has never left position .
Testdata Properties:
- Testdata - satisfy .
- Testdata - satisfy .
- Testdata - have no additional constraints.
Problem credits: Chris Zhang.
Translated by ChatGPT 5