Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
24044 | fyq & jbh's LCA | 【BJ】T1 | C++ | 运行出错 | 5 | 58 MS | 13696 KB | 1282 | 2023-12-09 08:43:35 |
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define p_b push_back using namespace std; typedef long long ll; const int maxn=2e5+10,mod=998244353; inline ll read(){ ll x=0;short t=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n,a[maxn],dep[maxn],res; vector<int>v[maxn]; void dfs(int u,int fa){ for(int x:v[u])if(x!=fa){ dep[x]=dep[u]+1;dfs(x,u); } }bool chk(vector<int>v){ for(int x:v){ dep[x]=0;dfs(x,0); bool f=1; for(int y:v)if(dep[y]>a[y]){f=0;break;} if(f)return 1; }return 0; } void DFS(int x,vector<int>v){ if(x>n){ if(chk(v))res+=(1<<int(v.size())); return; }DFS(x+1,v); v.p_b(x); DFS(x+1,v); v.pop_back(); } void slv(){ n=read();up(i,1,n)a[i]=read(); up(i,1,n-1){int x=read(),y=read();v[x].p_b(y),v[y].p_b(x);} assert(n<=8); vector<int>g; DFS(1,g); cout<<res<<'\n'; }int main(){ // freopen("tree.in","r",stdin); // freopen("tree.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }