A814.Dance Mooves--Gold

提高+/省选-

USACO

通过率:0%

时间限制:1.00s

内存限制:128MB

题目描述

Farmer John鈥檚 cows are showing off their new dance mooves!
At first, all NN cows (2N1052\le N\le 10^5) stand in a line with cow ii in the
iith position in line. The sequence of dance mooves is given by KK (1K21051\le K\le 2\cdot 10^5) pairs of positions (a1,b1),(a2,b2),,(aK,bK)(a_1,b_1), (a_2,b_2), \ldots, (a_{K},b_{K}). In each minute i=1Ki = 1 \ldots K of the dance, the cows in
positions aia_i and bib_i in line swap. The same KK swaps happen again in
minutes K+12KK+1 \ldots 2K, again in minutes 2K+13K2K+1 \ldots 3K, and so on,
continuing indefinitely in a cyclic fashion. In other words,

  • In minute 11, the cows at positions a1a_1 and b1b_1 swap.
  • In minute 22, the cows at positions a2a_2 and b2b_2 swap.
  • ...
  • In minute KK, the cows in positions aKa_{K} and bKb_{K} swap.
  • In minute K+1K+1, the cows in positions a1a_{1} and b1b_{1} swap.
  • In minute K+2K+2, the cows in positions a2a_{2} and b2b_{2} 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 NN and KK. Each of the next KK lines
contains (a1,b1)(aK,bK)(a_1,b_1) \ldots (a_K, b_K) (1ai<biN1\le a_i<b_i\le N).

输出格式

Print NN lines of output, where the iith line contains the number of unique
positions that cow ii reaches.

输入输出样例

  • 输入#1

    5 4
    1 3
    1 2
    2 3
    2 4
    

    输出#1

    4
    4
    3
    4
    1
    

说明/提示

  • Cow 11 reaches positions 1,2,3,4\\{1,2,3,4\\}.
  • Cow 22 reaches positions 1,2,3,4\\{1,2,3,4\\}.
  • Cow 33 reaches positions 1,2,3\\{1,2,3\\}.
  • Cow 44 reaches positions 1,2,3,4\\{1,2,3,4\\}.
  • Cow 55 never moves, so she never leaves position 55.
首页