Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 50025;
- int n,tot,pre[N];
- vector<int> g[N];
- void dfs(int i) {
- pre[i] = ++tot;
- for(int j:g[i]) dfs(j);
- }
- signed main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- cin >> n;
- for(int i = 1, k; i <= n; i++) {
- cin >> k;
- g[i].resize(k);
- for(int &j: g[i]) cin >> j;
- }
- dfs(1);
- for(int i = 1; i <= n; i++) cout << pre[i] << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement