HDU 3342 Legal or Not (有向图的拓扑排序)
来源:互联网 发布:桌椅板凳淘宝 编辑:程序博客网 时间:2024/05/29 17:01
Legal or Not
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 700 Accepted Submission(s): 295
Problem Description
ACM-DIYis a large QQ group where many excellent acmers get together. It is soharmonious that just like a big family. Every day,many "holy cows" likeHH, hh, AC, ZT, lcc, BF, Qinz and so on chat on-line to exchange theirideas. When someone has questions, many warm-hearted cows like Lostwill come to help. Then the one being helped will call Lost "master",and Lost will have a nice "prentice". By and by, there are many pairsof "master and prentice". But then problem occurs: there are too manymasters and too many prentices, how can we know whether it is legal ornot?
We all know a master can have many prentices and a prenticemay have a lot of masters too, it's legal. Nevertheless,some cows arenot so honest, they hold illegal relationship. Take HH and 3xian forinstant, HH is 3xian's master and, at the same time, 3xian is HH'smaster,which is quite illegal! To avoid this,please help us to judgewhether their relationship is legal or not.
Please note thatthe "master and prentice" relation is transitive. It means that if A isB's master ans B is C's master, then A is C's master.
We all know a master can have many prentices and a prenticemay have a lot of masters too, it's legal. Nevertheless,some cows arenot so honest, they hold illegal relationship. Take HH and 3xian forinstant, HH is 3xian's master and, at the same time, 3xian is HH'smaster,which is quite illegal! To avoid this,please help us to judgewhether their relationship is legal or not.
Please note thatthe "master and prentice" relation is transitive. It means that if A isB's master ans B is C's master, then A is C's master.
Input
Theinput consists of several test cases. For each case, the first linecontains two integers, N (members to be tested) and M (relationships tobe tested)(2 <= N, M <= 100). Then M lines follow, each containsa pair of (x, y) which means x is y's master and y is x's prentice. Theinput is terminated by N = 0.
TO MAKE IT SIMPLE, we give every one a number (0, 1, 2,..., N-1). We use their numbers instead of their names.
TO MAKE IT SIMPLE, we give every one a number (0, 1, 2,..., N-1). We use their numbers instead of their names.
Output
For each test case, print in one line the judgement of the messy relationship.
If it is legal, output "YES", otherwise "NO".
If it is legal, output "YES", otherwise "NO".
Sample Input
3 20 11 22 20 11 00 0
Sample Output
YESNO
解题思路:
有向图的拓扑排序。
- HDU 3342 Legal or Not (有向图的拓扑排序)
- 【拓扑排序】hdu 3342 Legal or Not
- 【HDU】3342 Legal or Not 拓扑排序
- hdu 3342 Legal or Not 拓扑排序
- HDU 3342 Legal or Not (拓扑排序)
- 拓扑排序 HDU 3342 Legal or Not
- hdu 3342 Legal or Not 拓扑排序
- HDU 3342 Legal or Not (拓扑排序)
- HDOJ 3342 Legal or Not(拓扑排序判断有向图是否存在环)
- hdu 3342 Legal or Not(DAG的拓扑排序)
- hdu—3342 Legal or Not 拓扑图的搜索
- hdu 3342 Legal or Not(给一个有向图判断该图是否拓扑有序)
- hdu 3342 Legal or Not(拓扑排序)
- hdu 3342 Legal or Not ( 拓扑排序 )
- hdu 3342 Legal or Not(拓扑排序dfs)
- hdu-3342-Legal or Not--拓扑排序//两种解法
- hdu 3342 Legal or Not(拓扑排序)
- hdu 3342 Legal or Not (拓扑排序)
- WMI event查询导致的内存quota violation错误
- 需求的概念和层次
- 没事写两条SQL语句
- CSS设计彻底研究
- NHibernate和Spring.Net框架介绍(一)
- HDU 3342 Legal or Not (有向图的拓扑排序)
- iis权限如何设置?
- 关于flex 中event 被触发的问题
- 按位反转整数问题
- NHibernate和Spring.Net框架介绍(二)
- ByteArray各方法详解
- Spring应用的单元测试
- 也谈需求调研
- PHP autoload机制详解