Padel Prize Pursuit

Time limit: 2s
Memory limit: 128MB
Input:
Output:

There are NN participants numbered 00 to N1N − 1 competing in a padel tournament held over MM days. Exactly one match is held each day. There are MM medals handed out in the tournament, a new one for each match. In the match on day i (0iM1)i \ (0 ≤ i ≤ M − 1), the two participants numbered xix_i and yiy_i are participating. The following happens in the match:

  • Participant xix_i beats participant yiy_i.
  • A new medal is given to the winner xix_i.
  • All of the loser's current medals are given to the winner.

On day MM (the day after the last match) the prize ceremony is held. At the ceremony, all medals are collected and then each medal is given to the participant that held that medal the longest. Formally, medal ii is given to the participant who held medal ii for the most nights (not necessarily in a row), as of day MM. If two or more participants have held a medal for the same number of nights, the medal is given to the participant with the smallest index among them.

Your goal is to determine how many medals each participant is awarded at the prize ceremony.

Input

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

Then MM lines follow. The iith of these lines contains two integers xix_i and yiy_i, the participants competing on day ii, where participant xix_i beats participant yiy_i.

Output

On the single line of output print NN integers, the kkth number representing the number of medals that participant kk has after the prize ceremony.

Constraints and Scoring

  • 2N200 0002 \leq N \leq 200 \ 000
  • 1M100 0001 \leq M \leq 100 \ 000
  • 0xi,yiN10 ≤ x_i, y_i ≤ N − 1 and xiyi (x_i ≠ y_i \ (for all 0iM1)0 ≤ i ≤ M − 1).

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

# Score Limits
1 12 N=2N = 2
2 16 N,M2 000N, M \leq 2 \ 000
3 15 The winner of the iith match participates in the (i+1)(i + 1)th match, for every ii such that 0iM20 ≤ i ≤ M − 2
4 20 At the time of the iith match, xix_i has at least as many medals as yiy_i , for every ii such that 0iM10 ≤ i ≤ M − 1.
5 22 Once a participant loses, they are never in a match again.
6 15 No additional constraints.

Example 1

stdin

3 4
0 1
2 1
1 0
2 1

stdout

1 1 2

Explanation

For the first sample test case, the following illustration shows who held which medals throughout the tournament. When participant 11 loses on the 33rd day, all her medals are given to participant 22.

Example 2

stdin

3 7
0 1
0 2
2 0
0 1
1 0
2 0
0 2

stdout

2 2 3

Explanation

The second sample can be seen below.

After the prize ceremony, participant 00 is given medals 55 and 66, participant 11 is given medals 33 and 44, and participant 22 is given medals 0,10, 1 and 22.

Example 3

stdin

6 10
2 5
3 0
4 2
0 1
4 3
2 4
0 3
0 2
5 2
5 0

stdout

5 0 1 1 1 2

Problem info

ID: 980

Editors:

Author:

Source: EGOI 2023: Day 1, Problem 2

Tags:

EGOI 2023 Day 1

Log in or sign up to be able to send submissions!