列表

详情


NC222454. [USACOJan2021G&S]DanceMooves

描述

Farmer John’s cows are showing off their new dance mooves!
At first, all N cows (2≤N≤105) stand in a line with cow i in the ith position in line. The sequence of dance mooves is given by K (1≤K≤2⋅105) pairs of positions (a1,b1),(a2,b2),…,(aK,bK). In each minute i=1…K of the dance, the cows in positions ai and bi in line swap. The same K swaps happen again in minutes K+1…2K, again in minutes 2K+1…3K, and so on, continuing in a cyclic fashion for a total of M minutes (1≤M≤1018). In other words,

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 N, K, and M. Each of the next K lines contains  (a1,b1),(a2,b2),…,(aK,bK) (1≤ai<bi≤N).

输出描述

Print N lines of output, where the ith line contains the number of unique positions that cow i reaches.

示例1

输入:

6 4 7
1 2
2 3
3 4
4 5

输出:

5
4
3
3
3
1

说明:

After 7 minutes, the cows in increasing order of position are [3,4,5,2,1,6].

Cow 1 reaches positions {1,2,3,4,5}.
Cow 2 reaches positions {1,2,3,4}.
Cow 3 reaches positions {1,2,3}.
Cow 4 reaches positions {2,3,4}.
Cow 5 reaches positions {3,4,5}.
Cow 6 never moves, so she never leaves position 6.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

上一题