hdu 3342 Legal or Not (拓扑排序)

重边这样的东西   仅仅能呵呵

就是裸裸的拓扑排序

假设恩可以排出来就YES 。

else  NO

仅仅须要所有搜一遍就好了

#include <cstdio>
#include <cstring>
int mapp[101][101];
int d[101];
int n,m;
int a,b;
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0)break;
    	memset(d,0,sizeof(d));
    	memset(mapp,0,sizeof(mapp));
    	for(int i=0;i<m;i++){
    		scanf("%d%d",&a,&b);
    		if(!mapp[a][b])d[b]++;
    		mapp[a][b]=1;
    	}
    	int flag=1;
    	for(int i=0;i<n;i++){
    		int j;
    		for(j=0;j<n;j++){
    		if(d[j]==0){
    			d[j]--;
                for(int k=0;k<n;k++)
                if(mapp[j][k]){
                	d[k]--;
                }
                break;
    		}
    	}
    		if(j>=n)
    		{
                flag=0;
                break;
    		}
    	}
    	if(flag)puts("YES");
    	else puts("NO");
    }
}
/*又有重边,哈哈*/
时间: 2024-07-28 20:29:18

hdu 3342 Legal or Not (拓扑排序)的相关文章

hdu 3342 Legal or Not - 拓扑排序

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

hdu 3342 Legal or Not 拓扑排序判断环。 现在的我,除了刷水题,,还能干什么

Legal or Not Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4960    Accepted Submission(s): 2270 Problem Description ACM-DIY is a large QQ group where many excellent acmers get together. It is

HDU 1258 确定比赛名次 &amp;&amp;HDU 3342 Legal or Not 【临接表+拓扑排序】

HDU 1258 链接:click here HDU 3342 链接:click here 题意: 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14142    Accepted Submission(s): 5667 Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,

[ACM] hdu 3342 Legal or Not (拓扑排序)

Legal or Not 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 excha

HDU 3213 Box Relations(拓扑排序构造)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3231 题意:有n个长方体,四种限制条件.(1)I x y x和y有相交:(2)X/Y/Z  x y x的最大X/Y/Z坐标小于y的最大X/Y/Z.构造出这样的n个长方体. 思路:首先,XYZ三个方向是可以分开考 虑的.那么我们可以一个个分别求解.将每个长方体拆成左上角右下角两个点,我们假设现在考虑X方向,也即是一个长方体对应两个X方向的点,共2*n个点, 边<i,j>表示i小于j,那么首先有边&l

HDU 2647 Reward(图论-拓扑排序)

Reward Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards. The workers will compare their rewards ,a

HDU 2467 Reward(逆拓扑排序)

拓扑排序的变形,逆序建图就好了 Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3951    Accepted Submission(s): 1203 Problem Description Dandelion's uncle is a boss of a factory. As the spring festival

HDU 4324 Triangle LOVE (拓扑排序)

Triangle LOVE Problem Description Recently, scientists find that there is love between any of two people. For example, between A and B, if A don't love B, then B must love A, vice versa. And there is no possibility that two people love each other, wh

HDU 3342 Legal or Not(拓扑排序判环)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3342 题目: 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, lc

HDU 3342 Legal or Not(拓扑排序判断成环)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3342 题目大意:n个点,m条有向边,让你判断是否有环. 解题思路:裸题,用dfs版的拓扑排序直接套用即可. 代码: 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int N=1e2+5; 6 7 int n,m; 8 int vis[N];