您的位置:首页 > 其它

【拓扑排序】CODEVS 2833 奇怪的梦境

2014-11-06 11:26 330 查看
拓扑排序模板。

#include<cstdio>
#include<vector>
#include<stack>
using namespace std;
#define N 10001
vector<int>G
;
stack<int>S;
int n,m,x,y,ru
,tot;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
G[x].push_back(y);
ru[y]++;
}
for(int i=1;i<=n;i++)
if(!ru[i])
S.push(i);
while(!S.empty())
{
int U=S.top(); S.pop();
tot++;
for(vector<int>::iterator it=G[U].begin();it!=G[U].end();it++)
if(!(--ru[*it]))
S.push(*it);
}
if(tot==n) puts("o(∩_∩)o");
else printf("T_T\n%d\n",n-tot);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: