#abc313b. B - Who is Saikyo?
B - Who is Saikyo?
Score : points
问题描述
有 名竞赛程序员,编号分别为 person 1、person 2、…、person 。
在这些程序员之间存在一种称为“优势”的关系。对于任意一对不同的程序员(person 和 person ),恰好满足以下两种关系之一:“person 比 person 更强”或“person 比 person 更强”。
这种优势关系具有传递性。换句话说,对于所有三元组不重复的程序员(person 、person 和 person ),满足以下条件:
- 如果 person 比 person 更强且 person 比 person 更强,那么 person 比 person 更强。
如果一名程序员 对于除自己以外的所有人 都更强,则称该程序员为最强程序员。(根据上述约束条件,我们可以证明总是存在唯一的一个这样的人。)
你手头有关于他们优势关系的 条信息。第 条信息是:“person 比 person 更强”。
你能根据这些信息确定这 名程序员中的最强程序员吗?
如果可以,请输出该程序员的编号。否则,即如果有多个可能的最强程序员时,请输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are competitive programmers numbered person , person , , and person .
There is a relation called superiority between the programmers. For all pairs of distinct programmers person , person , exactly one of the following two relations holds: "person is stronger than person " or "person is stronger than person ."
The superiority is transitive. In other words, for all triplets of distinct programmers person , person , person , it holds that:
- if person is stronger than person and person is stronger than person , then person is stronger than person .
A person is said to be the strongest programmer if person is stronger than person for all people other than person . (Under the constraints above, we can prove that there is always exactly one such person.)
You have pieces of information on their superiority. The -th of them is that "person is stronger than person ."
Can you determine the strongest programmer among the based on the information?
If you can, print the person's number. Otherwise, that is, if there are multiple possible strongest programmers, print -1
.
Constraints
- If , then .
- There is at least one way to determine superiorities for all pairs of distinct programmers, that is consistent with the given information.
Input
The input is given from Standard Input in the following format:
Output
If you can uniquely determine the strongest programmer, print the person's number; otherwise, print -1
.
Sample Input 1
3 2
1 2
2 3
Sample Output 1
1
You have two pieces of information: "person is stronger than person " and "person is stronger than person ."
By the transitivity, you can also infer that "person is stronger than person ," so person is the strongest programmer.
Sample Input 2
3 2
1 3
2 3
Sample Output 2
-1
Both person and person may be the strongest programmer. Since you cannot uniquely determine which is the strongest, you should print -1
.
Sample Input 3
6 6
1 6
6 5
6 2
2 3
4 3
4 2
Sample Output 3
-1
update @ 2024/3/10 08:55:03