#abc352f. F - Estimate Order
F - Estimate Order
Score: points
问题陈述
有 个人,编号为 到 。
在这些人之间举行了一场比赛,并且他们已经根据比赛结果进行了排名。关于他们的排名,给出了以下信息:
- 每个人都有一个独特的排名。
- 对于每个 ,如果第 个人排名第 ,第 个人排名第 ,那么 。
给定的输入保证至少存在一种排名,它不会与给定的信息相矛盾。
回答 个查询。第 个查询的答案如下确定:
- 如果可以唯一确定第 个人的排名,返回该排名。否则,返回 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There are people, numbered to .
A competition was held among these people, and they were ranked accordingly. The following information is given about their ranks:
- Each person has a unique rank.
- For each , if person is ranked -th and person is ranked -th, then .
The given input guarantees that there is at least one possible ranking that does not contradict the given information.
Answer queries. The answer to the -th query is an integer determined as follows:
- If the rank of person can be uniquely determined, return that rank. Otherwise, return .
Constraints
- There is at least one possible ranking that does not contradict the given information.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answers to the -st, -nd, , -th queries in this order, separated by spaces.
Sample Input 1
5 2
2 3 3
5 4 3
Sample Output 1
3 -1 -1 -1 -1
Let be the rank of person . Then, could be or .
Therefore, the answer to the -st query is , and the answers to the -nd, -rd, -th, and -th queries are .
Sample Input 2
3 0
Sample Output 2
-1 -1 -1
Sample Input 3
8 5
6 7 3
8 1 7
4 5 1
7 2 1
6 2 4
Sample Output 3
1 -1 -1 -1 -1 -1 -1 8