constint N = 1e3 + 9; constint INF = 0x3f3f3f3f; vector<int> g[N]; int n, x, in[N]; queue<int> q;
intmain() { // ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) while (cin >> x && x != 0) { g[i].push_back(x); in[x]++; } for (int i = 1; i <= n; i++) if (in[i] == 0) { cout << i << ' '; q.push(i); } while (!q.empty()) { int x = q.front(); q.pop(); for (auto i : g[x]) { in[i]--; if (in[i] == 0) { cout << i << ' '; q.push(i); } } } return0; }