45 lines
881 B
C++
45 lines
881 B
C++
#include <algorithm>
|
|
#include <array>
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <utility>
|
|
#include <vector>
|
|
using namespace std;
|
|
using ll = int64_t;
|
|
|
|
ll const maxn{2500+5};
|
|
ll n,ans;
|
|
array<ll,maxn> t,tmp;
|
|
vector<ll> adj[maxn];
|
|
|
|
void dfs(ll const& ftr, ll const& u){
|
|
for(ll const& v:adj[u]){
|
|
if(v==ftr)continue;
|
|
dfs(u,v);
|
|
tmp[u]+=12-tmp[v];
|
|
tmp[u]%=12;
|
|
if(tmp[u]==0)tmp[u]=12;
|
|
}
|
|
}
|
|
|
|
int main(){
|
|
cin.tie(nullptr),cout.tie(nullptr),ios::sync_with_stdio(false);
|
|
|
|
cin>>n;
|
|
for(ll i{1};i<=n;i++)cin>>t[i];
|
|
for(ll i{1};i<n;i++){
|
|
ll u,v;
|
|
cin>>u>>v;
|
|
adj[u].emplace_back(v);
|
|
adj[v].emplace_back(u);
|
|
}
|
|
|
|
for(ll i{1};i<=n;i++){
|
|
copy(t.data(),t.data()+1+n,tmp.data());
|
|
dfs(0,i);
|
|
if(tmp[i]==12||tmp[i]==1){
|
|
ans++;
|
|
}
|
|
}
|
|
cout<<ans<<'\n';
|
|
} |