#P9464. [EGOI 2023] Padel Prize Pursuit / 追梦笼式网球

[EGOI 2023] Padel Prize Pursuit / 追梦笼式网球

Background

Day 1 Problem B.

Translated from EGOI2023 ppp

CC BY-SA 3.0

Problem Description

There are NN players numbered from 00 to N1N-1 participating in a MM-day padel tournament. Each day, exactly one match is played. In total, MM medals are awarded during the tournament, and each match awards one new medal. In the match on day ii (0iM10\le i\le M-1), two players with numbers xix_i and yiy_i play. The following happens:

  • Player xix_i defeats player yiy_i.
  • A new medal is given to the winner xix_i.
  • All medals currently owned by the loser are given to the winner.

On day MM (the day after the last match), an award ceremony is held. At the ceremony, all medals are collected and awarded to the player who has held that medal for the most nights. Specifically, on day MM, medal ii is awarded to the player who has held medal ii for the largest number of nights (not necessarily continuously). If two or more players have held a medal for the same number of nights, the medal is awarded to the one with the smallest index.

Your task is to compute, at the award ceremony, how many medals each player is awarded.

Input Format

The first line contains two integers N,MN,M, representing the number of players and the number of matches.

The next MM lines each contain two integers xi,yix_i,y_i, meaning that in the match on day ii, player xix_i defeats player yiy_i.

Output Format

Output one line with NN integers. The kk-th integer is the number of medals awarded to player kk at the award ceremony.

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

Hint

Explanation of Sample 1

The figure below shows who owns each medal during the tournament in Sample 1. When player 11 is defeated on the third day, all of her medals are given to player 22.


Explanation of Sample 2

As shown in the figure below.

At the award ceremony, player 00 is awarded medals 55 and 66, player 11 is awarded medals 33 and 44, and player 22 is awarded medals 0,1,20,1,2.


Constraints

For all testdata, 2N2×1052\le N\le 2\times 10^5, 1M2×1051\le M\le 2\times 10^5, 0xi,yiN10\le x_i,y_i\le N-1 and xiyix_i\ne y_i.

  • Subtask 1 (1212 points): N=2N=2.
  • Subtask 2 (1616 points): N,M2×103N,M\le 2\times 10^3.
  • Subtask 3 (1515 points): The winner of match ii participates in match i+1i+1, depends on Subtask 1.
  • Subtask 4 (2020 points): In match ii, xix_i has at least as many medals as yiy_i.
  • Subtask 5 (2222 points): Once a player is defeated, she will never play again.
  • Subtask 6 (1515 points): No additional constraints, depends on Subtasks 2, 3, 4, and 5.

Translated by ChatGPT 5