标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15603 Accepted Submission(s): 6224
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; int indegree[1000],map[1000][1000]; int n,m; void toposort(){ int temp; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(!indegree[j]){ temp=j; break; } } printf("%d%c",temp,i==n?‘\n‘:‘ ‘); indegree[temp]--; for(int k=1;k<=n;k++){ if(map[temp][k]) indegree[k]--; } } } int main(){ while(scanf("%d%d",&n,&m)!=EOF){ memset(indegree,0,sizeof(indegree)); memset(map,0,sizeof(map)); int a,b; for(int i=1;i<=m;i++){ scanf("%d%d",&a,&b); if(!map[a][b]){ map[a][b]=1; indegree[b]++; } } toposort(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/13224ACMer/p/4638450.html