码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3342 Legal or Not

时间:2015-04-14 19:44:11      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:

和5154一模一样,不想说什么

#include<iostream>
#include<queue>
#include<vector>
#define maxn 100+10
using namespace std;
int n,m;
int head[maxn];
vector<vector<int> >mapp;
void topo()
{
	queue<int>root;
	for(int i=0;i<n;i++)
	{
		if(!head[i]) root.push(i);
	}
	int t=0;
	while(root.size())
	{
		int x=root.front();
		root.pop();
		t++;
		for(int i=0;i<mapp[x].size();i++)
		{
			head[mapp[x][i]]--;
			if(!head[mapp[x][i]]) root.push(mapp[x][i]);
		}
	}
	if(t==n) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}
int main()
{
	while(cin>>n>>m&&n)
	{
		mapp.resize(n+1);
		for(int i=0;i<n+1;i++) head[i]=0,mapp[i].clear();
		while(m--)
		{
			int x,y;
			cin>>x>>y;
			mapp[x].push_back(y);
			head[y]++; 
		}
		topo();
	}
	return 0;
} 


hdu 3342 Legal or Not

标签:

原文地址:http://blog.csdn.net/zafkiel_nightmare/article/details/45046403

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!