rt,感觉是很SB的错误,但看不出来,有没有过路大佬来调一调qwq
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
int n;
int a[N];
vector<int> e[N];
bool dfs(int x, int fa)
{
bool f = 0;
for(int i = 0; i < e[x].size(); i++)
{
if(e[x][i] == fa) continue;
if(!dfs(e[x][i], x) && a[i] > a[e[x][i]]) f = 1;
}
return f;
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i < n; i++)
{
int x, y;
cin >> x >> y;
e[x].push_back(y);
e[y].push_back(x);
}
for(int i = 1; i <= n; i++)
{
if(dfs(i, 0)) cout << i << " ";
}
return 0;
}