2014-07-09 02:27:23

题意&思路:裸拓扑,不赘述。

 1 #include <cstring>
 2 #include <iostream>
 3 using namespace std;
 4 int main(){
 5     int g[105][105],n,m,inc[105],ans[105],cnt,a,b,i,j;
 6     while(cin >> n >> m && (n || m)){
 7         memset(g,0,sizeof(g));
 8         memset(inc,0,sizeof(inc));
 9         cnt = 0;
10         for(i = 1; i <= m; ++i)
11             cin >> a >> b , g[a][b] = 1 , ++inc[b];
12         for(i = 1; i <= n; ++i){
13             for(j = 1; j <= n; ++j)
14                 if(inc[j] == 0)
15                     break;
16             inc[j] = -1; //delete this node
17             ans[cnt++] = j;
18             for(int k = 1; k <= n; ++k)
19                 if(g[j][k]) --inc[k];
20         }
21         cout << ans[0];
22         for(i = 1; i < cnt; ++i) cout << ' ' << ans[i];
23         cout << endl;
24     }
25     return 0;
26 }

 

相关文章:

  • 2021-11-12
  • 2022-12-23
  • 2021-06-23
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2021-12-07
猜你喜欢
  • 2021-11-05
  • 2021-05-20
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2018-03-24
  • 2022-12-23
相关资源
相似解决方案