EGOI '23 P2 - Padel Prize Pursuit

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 3.0s
Memory limit: 1G

Problem type
European Girls' Olympiad in Informatics: 2023 Day 1 Problem 2

There are N participants numbered 0 to N1 competing in a padel tournament held over M days. Exactly one match is held each day. There are M medals handed out in the tournament, a new one for each match. In the match on day i (0iM1), the two participants numbered xi and yi are participating. The following happens in the match:

  1. Participant xi beats participant yi.
  2. A new medal is given to the winner xi.
  3. All of the loser's current medals are given to the winner.

On day M (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 i is given to the participant who held medal i for the most nights (not necessarily in a row), as of day M. 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 Specification

The first line of input contains the integers N and M, the number of participants and the number of matches.

Then M lines follow. The ith of these lines contains two integers xi and yi, the participants competing on day i, where participant xi beats participant yi.

Output Specification

On the single line of output print N integers, the kth number denoting the number of medals that participant k has after the prize ceremony.

Constraints and Scoring

  • 2N200000.
  • 1M200000.
  • 0xi,yiN1 and xiyi (for all 0iM1).

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.

Group Score Limits
1 12 N=2
2 16 N,M2000
3 15 The winner of the i-th match participates in the i+1-th match, for every i such that 0iM2.
4 20 At the time of the i-th match, xi has at least as many medals as yi, for every i such that 0iM1.
5 22 Once a participant loses, they are never in a match again.
6 15 No additional constraints

Example

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 are given to participant 2.

The second sample can be seen below.

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

Sample Input 1

Copy
3 4
0 1
2 1
1 0
2 1

Sample Output 1

Copy
1 1 2

Sample Input 2

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

Sample Output 2

Copy
2 2 3

Sample Input 3

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

Sample Output 3

Copy
5 0 1 1 1 2

Comments

There are no comments at the moment.