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. 使用StringBuilder或StringBuffer简单优化

    使用StringBuilder或StringBuffer // join(["a", "b", "c"]) -> "a an ...

  2. [MAC OS] NSButton tag 获取

    @IBAction func switchContentLayout(_ sender: Any) { let button : NSButton = sender as! NSButton;}

  3. TFS WorkItem Permission Setting

    TFS非常强大,但是权限设置确实非常的恶心复杂,这貌似是一切NB又傲慢的软件的通病. 那么,在哪里设置 WorkItem 的权限呢? 第一步: 第二步: 第三步,下面你将一目了然. 第四步,Share ...

  4. sqlalchemy批量删除数据、全量删除

    问题:sqlalchemy如何批量删除多条数据解决:使用参数synchronize_session=False,或for循环方法:        users = self.db.query(User) ...

  5. 3维DEMO: 抽奖圆盘

    抽奖圆盘 前些日子去超市,消费满一定钱数可以参加抽奖,就是在电视机上有个可旋转的圆盘,按一键开始,按一键抽奖结束.看到最大奖的扇形区域大约有个10度角的样子,按说中大奖的概率应该是36分之1.当然,这 ...

  6. linux编程合并多个静态库.a为一个.a

    .a 文件的结构和.tar文件就没有什么区别. x 命令解出来, a 命令添加, t命令列表 假设A.a, B.a C.a 在/usr/local/lib目录下 mkdir /tmp/libABC c ...

  7. Informatica 常用组件Lookup之七 查找条件

    PowerCenter 使用查找条件来测试收到的值.这与 SQL 查询中的 WHERE 子句相似.为转换配置查找条件时,将对转换输入值和查找源或高速缓存(用查找端口代表)中的值进行比较.当您运行工作流 ...

  8. Spring 事务模板

    最近项目开发中需要用到单机事务,因为项目中使用了Spring和Mybatis框架,所以通过Spring来进行事务的管理,并且记录一下事务配置的过程 第一步:配置DataSource <!-- 发 ...

  9. [leetcode]Convert Sorted List to Binary Search Tree @ Python

    原题地址:http://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ 题意:将一条排序好的链表转换为二叉查找树 ...

  10. Spark性能优化(2)——广播变量、本地缓存目录、RDD操作、数据倾斜

    广播变量 背景 一般Task大小超过10K时(Spark官方建议是20K),需要考虑使用广播变量进行优化.大表小表Join,小表使用广播的方式,减少Join操作. 参考:Spark广播变量与累加器 L ...