← 返回 bytedance 的题目列表Determine Players with Unique Ranks from Match Results (Reachability Counts in a Directed Graph)
类型:online_judge
Problem: Determine Players with Uniquely Decidable Ranks from Match Results
There are n players with a true, unique ranking from 1..n (no ties). The rule is:
If player x is ranked higher than player y, then x will always beat y.
You are given m known match outcomes, each as a beat b, meaning a is definitely stronger than b (i.e., a must be ranked higher).
Your task is to find all players whose exact rank can be uniquely determined from the given outcomes, and output those ranks.
A player p has a uniquely decidable rank if:
the number of players that are definitely stronger than p (nodes that can reach p), plus
the number of players that are definitely weaker than p (nodes reachable from p)
equals n - 1.
Input Format
First line: two integers n m
Next m lines: two integers a b meaning a beat b
Output Format
Output multiple lines player rank for each player whose rank is uniquely determined.
Example
Input
5 4
1 2
2 3
1 3
4 5
Output
1 1
2 2
3 3
Explanation: the relative order among 1,2,3 is fully implied; players 4 and 5 cannot be placed uniquely in the global ranking.
Example
Input
5 4
1 2
2 3
1 3
4 5
Output
1 1
2 2
3 3