标签:put scanf miss using names 不能 limit inf 也有
C/C++:
1 #include <map> 2 #include <queue> 3 #include <cmath> 4 #include <vector> 5 #include <string> 6 #include <cstdio> 7 #include <cstring> 8 #include <climits> 9 #include <iostream> 10 #include <algorithm> 11 #define INF 0xffffff 12 using namespace std; 13 14 const int my_max_N = 505; 15 int my_indeg[my_max_N], n, m, a, b; 16 vector <int> my_G[my_max_N]; 17 18 void topsort() 19 { 20 queue <int> Q, ans; 21 22 while (1) 23 { 24 for (int i = 1; i <= n; ++ i) 25 if (my_indeg[i] == 0) 26 { 27 Q.push(i), ans.push(i); 28 my_indeg[i] = -1; 29 break; 30 } 31 32 if (Q.empty()) break; 33 while (!Q.empty()) 34 { 35 int my_now = Q.front(); 36 for (int i = 0; i < my_G[my_now].size(); ++ i) 37 -- my_indeg[my_G[my_now][i]]; 38 my_G[my_now].clear(); 39 Q.pop(); 40 } 41 } 42 43 /** 44 Answer Output 45 */ 46 printf("%d", ans.front()); 47 ans.pop(); 48 while (!ans.empty()) 49 { 50 printf(" %d", ans.front()); 51 ans.pop(); 52 } 53 printf("\n"); 54 } 55 56 int main() 57 { 58 while (~scanf("%d%d", &n, &m)) 59 { 60 memset(my_indeg, 0, sizeof (my_indeg)); 61 62 while (m --) 63 { 64 scanf("%d%d", &a, &b); 65 my_G[a].push_back(b); 66 ++ my_indeg[b]; 67 } 68 69 topsort(); 70 } 71 return 0; 72 }
标签:put scanf miss using names 不能 limit inf 也有
原文地址:https://www.cnblogs.com/GetcharZp/p/9457003.html