标签:排名 miss turn 表示 limit end i++ field 程序
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29120 Accepted Submission(s):
11601
1 #include "bits/stdc++.h" 2 using namespace std; 3 typedef long long LL; 4 const int MAX=505; 5 int n,m; 6 int a[MAX][MAX]; 7 int degree[MAX]; 8 priority_queue <int , vector<int>, greater<int> > q; 9 int main(){ 10 freopen ("sort.in","r",stdin); 11 freopen ("sort.out","w",stdout); 12 int i,j; 13 int u,v,x; 14 while (~scanf("%d%d",&n,&m)){ 15 while (q.size()) q.pop(); 16 memset(a,0,sizeof(a)); 17 memset(degree,0,sizeof(degree)); 18 for (i=1;i<=m;i++){ 19 scanf("%d%d",&u,&v); 20 if (a[u][v]==0){ 21 a[u][v]=1; 22 degree[v]++; 23 } 24 } 25 for (i=1;i<=n;i++){ 26 if (degree[i]==0){ 27 q.push(i); 28 } 29 } 30 x=0; 31 while (q.size()){ 32 x++; 33 u=q.top(); 34 q.pop(); 35 if (x==n) 36 printf("%d\n",u); 37 else 38 printf("%d ",u); 39 for (i=1;i<=n;i++){ 40 if (a[u][i]){ 41 degree[i]--; 42 if (degree[i]==0){ 43 q.push(i); 44 } 45 } 46 } 47 } 48 } 49 return 0; 50 }
标签:排名 miss turn 表示 limit end i++ field 程序
原文地址:http://www.cnblogs.com/keximeiruguo/p/7583248.html