%: pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 50;
vector<int> g[maxn];
bool vis[maxn], use[maxn];
int num[maxn], n;
int main(){
//  freopen("C.in", "r", stdin);
//  freopen("C.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &num[i]);
    for (int i = 1; i < n; ++i){
        int u, v; scanf("%d%d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    memset(vis, false, sizeof(vis));
    for (int i = 1; i <= n; ++i){
        bool ok = true;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] < num[i]){ok = false; break;}
        }
        if (ok) vis[i] = true;
    }
//  for (int i = 1; i <= n; ++i) if (vis[i]) cout << i << endl;
    vector<int> ans;
    memset(use, false, sizeof(use)); // true -> ±ØÊ¤µã
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (!vis[i] && !use[i]){
        bool ok = false;
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (num[v] >= num[i] || use[v]) continue;
            ok = true;
        }
        if (!ok) vis[i] = true;
    }
    for (int i = 1; i <= n; ++i) if (vis[i]){
        for (int j = 0; j < (int)g[i].size(); ++j){
            int v = g[i][j]; if (vis[v] || use[v] || num[v] <= num[i]) continue;
            use[v] = true;
        }
    }
    for (int i = 1; i <= n; ++i) if (use[i]) printf("%d ", i);
    //     ans.push_back(i);  
    // for (int i = 0; i < (int)ans.size(); ++i) printf("%d ", ans[i]);
    return 0;
}

Measured memory_bytes: 27648