Under construction

Still being built. Things may change

Padel Prize Pursuit

Time limit3sMemory limit1024 MB

Summary
Given M matches where the winner gains a medal and takes the loser's medals, assign each medal to its longest holder and count medals per participant.
Level

Medium7 of 10

Topics
Union-find, Array, Implementation
Solved
No attempts yet

Problem

There are NN participants numbered 00 to N−1N-1 in a padel tournament that lasts MM days. Exactly one match is played each day. One medal is handed out per match, so there are MM medals in total. On day ii (0≤i≤M−1)(0 \le i \le M-1), participants xix_i and yiy_i play. The match goes as follows:

  1. Participant xix_i beats participant yiy_i.
  2. A new medal goes to the winner xix_i.
  3. All of the loser's current medals go to the winner.

On day MM, the day after the last match, the prize ceremony is held. At the ceremony, all medals are collected. Each medal then goes to the participant who held it for the most nights as of day MM. The nights do not need to be consecutive. If two or more participants held a medal for the same number of nights, the medal goes to the one with the smallest index. Find how many medals each participant receives at the ceremony.

Input

The first line contains the integers NN and MM, the number of participants and the number of matches.

The next MM lines each contain two integers xix_i and yiy_i. Line ii gives the participants of the match on day ii, where xix_i beats yiy_i.

Output

Print NN integers on a single line. The kkth integer is the number of medals participant kk has after the prize ceremony.

Constraints

  • 2≤N≤200 0002 \leq N \leq 200\,000.
  • 1≤M≤200 0001 \leq M \leq 200\,000.
  • 0≤xi,yi≤N−10 \le x_i, y_i \le N-1 and xi≠yix_i \neq y_i (for all 0≤i≤M−10 \le i \le M-1).

Hints

For the first sample test case, the following illustration shows who held which medals throughout the tournament. When participant 1 loses on the 3rd day, all her medals go to participant 2.

The second sample is shown below.

After the prize ceremony, participant 0 gets medals 5 and 6, participant 1 gets medals 3 and 4, and participant 2 gets medals 0, 1, and 2.

Examples3

  1. Example 1

    Input
    3 4
    0 1
    2 1
    1 0
    2 1
    
    Expected output
    1 1 2
    
  2. Example 2

    Input
    3 7
    0 1
    0 2
    2 0
    0 1
    1 0
    2 0
    0 2
    
    Expected output
    2 2 3
    
  3. Example 3

    Input
    6 10
    2 5
    3 0
    4 2
    0 1
    4 3
    2 4
    0 3
    0 2
    5 2
    5 0
    
    Expected output
    5 0 1 1 1 2