#include <iostream> #include <queue> #include <vector> #include <cstring> using namespace std; const int N = 1e5+10; vector<int> g[N]; int d[N], n; void topsort(){ priority_queue<int, vector<int>, greater<int>> q; //字典序最小 for(int i = 0; i < n; i ++){ if(!d[i]) q.push(i); } while(q.size()){ int t = q.top(); cout<<"Task"<<t<<' '; q.pop(); for(auto i : g[t]){ if(--d[i] == 0) q.push(i); } } cout<<endl; } int main(){ while(cin>>n){ string s; cin>>s; memset(d, 0, sizeof d); g[N].clear(); if(s[6] != 'N'){ for(int i = 10; i < s.size(); i += 6){ int a = s[4] - '0'; int b = s[i] - '0'; g[a].push_back(b); d[b] ++; } } topsort(); } return 0; }
麻烦的是字符串~