CF412D.Giving Awards
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else.
Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one for the hard work this month. The CEO knows who owes money to whom. And he also understands that if he invites person x to his office for a reward, and then immediately invite person y, who has lent some money to person x, then they can meet. Of course, in such a situation, the joy of person x from his brand new money reward will be much less. Therefore, the R1 CEO decided to invite the staff in such an order that the described situation will not happen for any pair of employees invited one after another.
However, there are a lot of employees in the company, and the CEO doesn't have a lot of time. Therefore, the task has been assigned to you. Given the debt relationships between all the employees, determine in which order they should be invited to the office of the R1 company CEO, or determine that the described order does not exist.
R1 公司的员工经常一起度过闲暇时光:观看足球比赛、外出露营、共同解题竞赛等。因此,有时某位员工为另一位员工代付费用,也并不奇怪。
今天是发放奖金的日子。R1 公司首席执行官(CEO)将依次邀请员工进入其办公室,为每位员工颁发本月辛勤工作的奖金。CEO 清楚地知道员工之间谁欠谁的钱。此外,他还意识到:如果他先邀请员工 x 进入办公室领取奖金,紧接着又邀请员工 y 进入办公室,而 y 曾向 x 借出过钱,那么这两人就可能在办公室外相遇。显然,在这种情况下,员工 x 领取崭新奖金时的喜悦之情将大打折扣。因此,R1 公司 CEO 决定以某种顺序邀请员工,使得对任意两个连续被邀请的员工,都不会出现上述情形。
然而,公司员工人数众多,而 CEO 时间有限。因此,这项任务交由你来完成:给定所有员工之间的债务关系,请确定一种满足要求的邀请顺序;若不存在这样的顺序,则判定其不存在。
输入格式
The first line contains space-separated integers n and m
— the number of employees in R1 and the number of debt relations. Each of the following m lines contains two space-separated integers a__i, b__i (1 ≤ a__i, b__i ≤ n; a__i ≠ b__i), these integers indicate that the person number a__i owes money to a person a number b__i. Assume that all the employees are numbered from 1 to n.
It is guaranteed that each pair of people p, q is mentioned in the input data at most once. In particular, the input data will not contain pairs p, q and q, p simultaneously.
第一行包含两个用空格分隔的整数 n 和 m
,分别表示 R1 公司的员工人数以及债务关系数量。接下来的 m 行中,每行包含两个用空格分隔的整数 ai、bi(满足 1 ≤ ai, bi ≤ n 且 ai = bi),表示编号为 ai 的人欠编号为 bi 的人钱。假设所有员工编号均为 1 到 n。
保证任意一对人员 p、q 在输入数据中至多出现一次。特别地,输入数据中不会同时包含 (p,q) 和 (q,p) 这两对。
输出格式
Print -1 if the described order does not exist. Otherwise, print the permutation of n distinct integers. The first number should denote the number of the person who goes to the CEO office first, the second number denote the person who goes second and so on.
If there are multiple correct orders, you are allowed to print any of them.
如果所描述的顺序不存在,则输出 -1。否则,输出一个由 n 个互不相同的整数组成的排列。第一个数表示第一个前往 CEO 办公室的人的编号,第二个数表示第二个前往的人的编号,依此类推。
如果存在多个正确的顺序,你可以输出其中任意一个。
输入输出样例
输入#1
2 1 1 2
输出#1
2 1
输入#2
3 3 1 2 2 3 3 1
输出#2
2 1 3
输入解题思路,AI测评打分。不知道怎么写?