Padel Prize Pursuit
Time limit3sMemory limit1024 MB
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 participants numbered to in a padel tournament that lasts days. Exactly one match is played each day. One medal is handed out per match, so there are medals in total. On day , participants and play. The match goes as follows:
- Participant beats participant .
- A new medal goes to the winner .
- All of the loser's current medals go to the winner.
On day , 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 . 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 and , the number of participants and the number of matches.
The next lines each contain two integers and . Line gives the participants of the match on day , where beats .
Output
Print integers on a single line. The th integer is the number of medals participant has after the prize ceremony.
Constraints
- .
- .
- and (for all ).
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.