#P7299. [USACO21JAN] Dance Mooves S
[USACO21JAN] Dance Mooves S
Description
Farmer John’s cows are showing off their latest dance moves.
At the beginning, all cows () stand in a line, and cow is in the -th position. The dance move sequence is given as () pairs of positions . In minute of the dance, the cows at positions and swap places. The same swaps happen again in minutes , again in minutes , and so on, repeating forever. In other words,
- In minute , the cows at positions and swap places.
- In minute , the cows at positions and swap places.
- In minute , the cows at positions and swap places.
- In minute , the cows at positions and swap places.
- In minute , the cows at positions and swap places.
- And so on.
For each cow, find how many distinct positions in the line she will ever occupy.
Input Format
The first line contains and . The next lines each contain ().
Output Format
Output lines. The -th line contains the number of distinct positions that cow can reach.
5 4
1 3
1 2
2 3
2 4
4
4
3
4
1
Hint
- Cow can reach positions .
- Cow can reach positions .
- Cow can reach positions .
- Cow can reach positions .
- Cow never moves, so she never leaves position .
Test Point Properties:
- Test points 1-5 satisfy .
- Test points 6-10 satisfy .
- Test points 11-20 have no additional constraints.
Problem provided by: Chris Zhang.
Translated by ChatGPT 5
京公网安备 11011102002149号