302163: CF412D. Giving Awards

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Giving Awards

题意翻译

## 问题描述 R1 公司的员工们喜欢一起消磨时间,他们一起看球赛,一起去野餐,一起做 Codeforces 的比赛。所以,一个人替另一个人结账是没什么大不了的事情。 今天是发奖金的日子,R1 公司的 CEO 会把员工一个一个请到他的办公室去,按照他们这个月的工作努力程度发奖金。CEO 知道谁欠谁的钱,而且他知道,如果他邀请 $x$ 去他的办公室,然后马上邀请 $y$ 去他办公室,且 $y$ 借给了 $x$ 一些钱,那么他们就能相遇,发生比较尴尬的事情,然后 $x$ 得到的钱就变少了。因此,R1 公司的 CEO 决定按照一个合适的顺序(即上述情况不会发生在任意一对员工之间)邀请员工。 但是,由于员工特别多,CEO 的时间是有限的,于是这个安排顺序的工作就落在了你的手中。给你员工之间的所有债务关系,请你为 R1 公司的 CEO 决定一个邀请员工的顺序。 ## 输入格式 第一行两个整数 $n,m$,表示员工的数量和债务关系的数量。 接下来 $m$ 行每行两个数 $a,b$,表示员工 $a$ 欠 $b$ 钱。 每对人只会被提到一次。 ## 输出格式 输出一个长度为 $n$ 的序列,第一个数为第一个邀请的员工编号,第二个为第二个邀请的员工编号,以此类推。 如果不存在合适的方案,只输出一个 $-1$。

题目描述

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.

输入输出格式

输入格式


The first line contains space-separated integers $ n $ and $ m $ ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF412D/1595a9befef7bb5208740d9c7a03fc9f267d035a.png) — 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.

输出格式


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

2 1
1 2

输出样例 #1

2 1 

输入样例 #2

3 3
1 2
2 3
3 1

输出样例 #2

2 1 3 

Input

题意翻译

## 问题描述 R1 公司的员工们喜欢一起消磨时间,他们一起看球赛,一起去野餐,一起做 Codeforces 的比赛。所以,一个人替另一个人结账是没什么大不了的事情。 今天是发奖金的日子,R1 公司的 CEO 会把员工一个一个请到他的办公室去,按照他们这个月的工作努力程度发奖金。CEO 知道谁欠谁的钱,而且他知道,如果他邀请 $x$ 去他的办公室,然后马上邀请 $y$ 去他办公室,且 $y$ 借给了 $x$ 一些钱,那么他们就能相遇,发生比较尴尬的事情,然后 $x$ 得到的钱就变少了。因此,R1 公司的 CEO 决定按照一个合适的顺序(即上述情况不会发生在任意一对员工之间)邀请员工。 但是,由于员工特别多,CEO 的时间是有限的,于是这个安排顺序的工作就落在了你的手中。给你员工之间的所有债务关系,请你为 R1 公司的 CEO 决定一个邀请员工的顺序。 ## 输入格式 第一行两个整数 $n,m$,表示员工的数量和债务关系的数量。 接下来 $m$ 行每行两个数 $a,b$,表示员工 $a$ 欠 $b$ 钱。 每对人只会被提到一次。 ## 输出格式 输出一个长度为 $n$ 的序列,第一个数为第一个邀请的员工编号,第二个为第二个邀请的员工编号,以此类推。 如果不存在合适的方案,只输出一个 $-1$。

加入题单

算法标签: