标签:des style blog http color os strong io
Description
Input
Output
Sample Input
Sample Output
#include <stdio.h> #include <string.h> int map[502][502]; int in[502]; int s[502], k; int n; void toposort() { k = 0; int i, j; int dd = n; while(dd--) { for(i=1; i<=n; i++) { if(in[i]==0) { s[k++] = i; in[i]-=1; for(j=1; j<=n; j++) { if(map[i][j] == 1) { in[j]-=1; } } break; //找到了要输的人,现在就跳出 } } } for(j=0; j<k; j++) { printf("%d%c", s[j], j==k-1?‘\n‘:‘ ‘ ); } } int main() { int m; int i; int u, v; while(scanf("%d %d", &n, &m )!=EOF ) { memset(map, 0, sizeof(map )); memset(in, 0, sizeof(in)); for(i=0; i<m; i++) { scanf("%d %d", &u, &v ); if(map[u][v]==0) { map[u][v] = 1; in[v] ++; } } toposort(); } return 0; }
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/yspworld/p/3884132.html