Legal or Not

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3454    Accepted Submission(s): 1569

Problem Description
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.

 
Input
The 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.
 
Output
For each test case, print in one line the judgement of the messy relationship.
If it is legal, output "YES", otherwise "NO".
 
Sample Input
3 2 0 1 1 2 2 2 0 1 1 0 0 0
 
Sample Output
YES NO
 
Author
QiuQiu@NJFU
 
Source
 
简单的拓扑排序。。。。
本题的思路直接球有没有拓扑图是否成唤,即可 。。。
代码:
 /*@coder 龚细军*/
#include<stdio.h>
#include<string.h>
#define maxn 100
bool rea[maxn][maxn] ; /*rea--->realationship*/
int inde[maxn]; /*inde---->indegree*/
int n,m;
void tp_sort()
{
int i,j,k;
for(i=;i<n;i++)
{
for(j=;j<n;j++)
{
if(inde[j]==)
{
inde[j]--;
for(k=;k<n;k++)
{
if(rea[k][j])
{
inde[k]--;
}
}
break;
}
}
if(j==n)
{
printf("NO\n");
return ;
}
}
printf("YES\n");
return ;
} int main()
{ int a,b;
while(scanf("%d%d",&n,&m),n+m)
{
memset(rea,,sizeof(rea));
memset(inde,,sizeof(inde));
while(m--)
{
scanf("%d%d",&a,&b);
if(!rea[a][b]) /*a-->b*/
{
rea[a][b]=true;
inde[a]++;
}
}
tp_sort();
}
return ;
}

HDUOJ----3342Legal or Not的更多相关文章

  1. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  2. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  3. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  4. hdu-oj 1874 畅通工程续

    最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...

  5. C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...

  6. C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...

  7. HDUOJ题目HTML的爬取

    HDUOJ题目HTML的爬取 封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可. 其实没什么难度,先爬下来一个题目的 ...

  8. hduoj 1251 统计难题

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  9. hduoj 1286 找新朋友

    http://acm.hdu.edu.cn/showproblem.php?pid=1286 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  10. hduoj 1285 确定比赛名次

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...

随机推荐

  1. Win8 下配置Java开发环境

    背景: 大学期间学习过一段时间的JavaEE.不算很熟悉. 后来学习并在工作中很多其它是iOS开发,iOS的水平属于中上. 对技术已经有一定熟知程度. 近期为了写一些东西,须要用到Java写后台. 流 ...

  2. NLP知识十大结构

    NLP知识十大结构 2.1形式语言与自动机 语言:按照一定规律构成的句子或者字符串的有限或者无限的集合. 描述语言的三种途径: 穷举法 文法(产生式系统)描述 自动机 自然语言不是人为设计而是自然进化 ...

  3. 【BZOJ】【3437】小P的牧场

    DP/斜率优化 斜率优化基本题……等等,好像就没啥变化啊= = 嗯目测这题跟仓库建设差不多?写题的时候倒是没想这么多……直接推了公式. $$f[i]=min\{f[j]+cal(j,i)+a[i]\} ...

  4. Java基础(四):Java Number & Math 类、Character 类、String 类、StringBuffer & StringBuilder 类

    一.Java Number & Math 类: 1.Number类: 一般地,当需要使用数字的时候,我们通常使用内置数据类型,如:byte.int.long.double 等.然而,在实际开发 ...

  5. Android -- Fragment注意事项

    ViewPager+Fragment 让Fragment成为ViewPager的一页时,FragmentManager会一直保存管理创建好了的Fragment,即使当前不是显示的这一页,Fragmen ...

  6. Windows下创建文件的权限问题

    在Windows下如果在某个目录下建立一个文件,那么新建立的文件会默认继承该目录的所有权限(父子关系) 如果将一个文件从一个目录移动到到另一个目录下,那么该文件的权限并不会继承自新目录的权限而是还保留 ...

  7. 【Nodejs】使用nimble串行化回调任务

    nodejs的nimble模块可以使我们对回调任务进行串行化,它需要先安装 #npm install nimble 用法也方便,示例代码如下: //========================== ...

  8. LoadRunner 测试 Mysql

    准备文件 1. 下载 MySQL LoadRunner libraries. 下载地址:http://files.cnblogs.com/files/xiaoxitest/MySQL_LoadRunn ...

  9. html5调用摄像头实现拍照

    技术时刻都在前进着.我们的需求也是时刻在改变着.最近在开发中遇到了用户进行账号注册时需要个人图像,网站提供自动拍照功能.还有在登录了PC之后,手机端进行登录时只需要扫描一下PC上的二维码就可以登录.这 ...

  10. MySQL中int(5) 中的5代表什么意思?

    对于INT型,MySQL支持指定显示宽度例如:int(5):表示如果数值宽度小于5位,则填满宽度,保证总宽度为5位.默认为int(11),配合zerofill可以看到效果. DROP TABLE IF ...