1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=105; 4 int n; 5 int in[N]; 6 vector<int>G[N]; 7 int main() 8 { 9 scanf("%d",&n); 10 queue<int>q; 11 for(int i=1;i<=n;i++) 12 { 13 int son; 14 while(cin>>son&&son) 15 { 16 in[son]++; 17 G[i].push_back(son); 18 } 19 } 20 for(int i=1;i<=n;i++) 21 if(!in[i])q.push(i); 22 23 while(q.size()) 24 { 25 auto u=q.front(); 26 printf("%d ",u); 27 q.pop(); 28 for(auto &v:G[u]) 29 { 30 in[v]--; 31 if(!in[v])q.push(v); 32 } 33 } 34 return 0; 35 }