奇怪的梦境

#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>
#define maxn 10000+10
short book[maxn]={0},x,y,s[maxn],top=0;
short du[maxn]={0};
short e[maxn][maxn];
int n,m;
int main()
{
cin>>n>>m;
int i,j,k;
for(i=1;i<=m;i++)
{
cin>>x>>y;
e[x][y]=1;
du[y]++;
}

for(i=1;i<=n;i++)
if(du[i]==0)
{
top++;
s[top]=i;
book[i]=1;
}
while(top>0)
{
int x=s[top];
top--;
for(i=1;i<=n;i++)
if(e[x][i]==1)
du[i]--;
for(i=1;i<=n;i++)
if(du[i]==0&&book[i]==0)
{
top++;
s[top]=i;
book[i]=1;
}
}
int flag=1,count=0;
for(i=1;i<=n;i++)
if(book[i]==0)
{
flag=0;
count++;
}

if(flag)
cout<<"o(∩_∩)o"<<endl;
else
cout<<"T_T"<<endl<<count<<endl;

return 0;
}

posted @ 2016-02-14 17:21  Minepressure  阅读(136)  评论(0编辑  收藏  举报