POJ2367(拓扑排序裸题
1 #include<iostream> 2 #include<vector> 3 #include<queue> 4 using namespace std; 5 typedef long long ll; 6 const int N = 150; 7 int in[N],n,r; 8 vector<int>ans; 9 vector<int>edge[N]; 10 priority_queue<int,vector<int>,greater<int> >priq; 11 int main(){ 12 ios::sync_with_stdio(0); 13 cin>>n; 14 for(int i = 1;i <= n;++i){ 15 while(cin>>r){ 16 if(r==0)break; 17 edge[i].push_back(r);in[r]++; 18 } 19 } 20 for(int i = 1;i <= n;++i)if(in[i]==0)priq.push(i); 21 while(!priq.empty()){ 22 23 int p = priq.top();priq.pop(); 24 ans.push_back(p); 25 for(int j = 0;j < edge[p].size();++j){ 26 int y = edge[p][j]