版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35649707/article/details/82591055
题解:
点
先手必败当且仅当不存在
,
且
先手必胜。
从小到大加点即可,时间复杂度 。
#include <bits/stdc++.h>
using namespace std;
const int RLEN=1<<18|1;
inline char nc() {
static char ibuf[RLEN],*ib,*ob;
(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
char ch=nc(); int i=0,f=1;
while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
return i*f;
}
const int N=3e3+50;
int n,a[N],b[N],p[N];
vector <int> edge[N];
inline bool cmp(const int &x,const int &y) {return a[x]<a[y];}
int main() {
n=rd();
for(int i=1;i<=n;i++) a[i]=rd();
for(int i=1;i<=n;i++) p[i]=i;
sort(p+1,p+n+1,cmp);
for(int i=1;i<n;++i) {
int x=rd(), y=rd();
edge[x].push_back(y);
edge[y].push_back(x);
}
for(int i=1;i<=n;i++) {
int u=p[i];
for(int e=edge[u].size()-1;e>=0;e--) {
int v=edge[u][e];
if(a[u]>a[v] && !b[v]) b[u]=1;
}
}
for(int i=1;i<=n;i++) if(b[i]) cout<<i<<' ';
}