博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3342 拓扑,是否存在环
阅读量:4170 次
发布时间:2019-05-26

本文共 2265 字,大约阅读时间需要 7 分钟。

ACM-DIY is a large QQ group where many excellent acmers get together. It is so harmonious that just like a big family. Every day,many "holy cows" like HH, hh, AC, ZT, lcc, BF, Qinz and so on chat on-line to exchange their ideas. When someone has questions, many warm-hearted cows like Lost will 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 pairs of "master and prentice". But then problem occurs: there are too many masters and too many prentices, how can we know whether it is legal or not? 
We all know a master can have many prentices and a prentice may have a lot of masters too, it's legal. Nevertheless,some cows are not so honest, they hold illegal relationship. Take HH and 3xian for instant, HH is 3xian's master and, at the same time, 3xian is HH's master,which is quite illegal! To avoid this,please help us to judge whether their relationship is legal or not. 
Please note that the "master and prentice" relation is transitive. It means that if A is B's master ans B is C's master, then A is C's master.
InputThe input consists of several test cases. For each case, the first line contains two integers, N (members to be tested) and M (relationships to be tested)(2 <= N, M <= 100). Then M lines follow, each contains a pair of (x, y) which means x is y's master and y is x's prentice. The input 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.OutputFor each test case, print in one line the judgement of the messy relationship. 
If it is legal, output "YES", otherwise "NO".Sample Input
3 20 11 22 20 11 00 0

Sample Output

YESNO
#include
#include
#include
#define maxn 600#include
#include
#include
#include
using namespace std;struct node{ int to,next;}edge[maxn];int first[maxn][2];int n,m;int index;void add(int a,int b){ edge[index].to=b; edge[index].next=first[a][1]; first[a][1]=index++; first[b][0]++;//rudu}/*要注意index的初始化,和edge[i] i的初始起点坐标*/int main(){ int a,b; while(cin>>n>>m,n||m) { index=1; set
Q; set
::iterator it=Q.begin(); vector
v; memset(first,0,sizeof(first)); memset(edge,0,sizeof(edge)); for(int i=0;i

转载地址:http://ohfai.baihongyu.com/

你可能感兴趣的文章
Save could not be completed. Eclipse国际化的问题解决
查看>>
Xblo(JSP+Servlet+JavaBean+Oracle单用户Blog)
查看>>
Unable to use IEC module under PortablePython_1.1_py2.5.4
查看>>
实用英文地址书写格式
查看>>
在oracle中通过connect by prior来实现递归查询!
查看>>
百度空间如何才能另存为 mht
查看>>
How to Reset or Change Microsoft Office 2007 Product License Key or Volume License Key (VLK)
查看>>
使用java concurrent调用xmlp api生成pdf
查看>>
Oracle日期计算之INTERVAL
查看>>
Oracle PL/SQL之EXCEPTION
查看>>
Oracle PL/SQL之EXCEPTION -- WHEN OTHERS THEN
查看>>
Oracle PL/SQL之VARCHAR2 QUALIFIER
查看>>
Oracle PL/SQL之处理index不连续的table类型变量
查看>>
Oracle PL/SQL之嵌套表(Nested Table)
查看>>
Oracle PL/SQL之令人不解的提示(nls_date_format)
查看>>
Oracle PL/SQL之GROUP BY ROLLUP
查看>>
Oracle PL/SQL之GROUP BY CUBE
查看>>
蓝桥杯2018省赛 - A3 乘积尾零
查看>>
蓝桥杯2018省赛 - A4 第几个幸运数
查看>>
命令窗口中javac(即javac.exe)不可用的原因
查看>>