This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//UNSTOPPABLE
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define tpii pair <pair <int,int> , int>
#define bruh cout << "NO\n"
using namespace std;
using namespace __gnu_pbds;
const int N = 3e5 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,m,d[N],ban[N],val[N],a[N];
vector <int> g[N];
set <int> ans,st;
void dfs(int v , int p = 0){
for(auto to : g[v]){
if(to == p) continue;
d[to] = d[v] + 1;
dfs(to , v);
}
if(p && !ban[d[v]]){
if(st.find(d[v]) != st.end()){
ban[d[v]] = 1;
}
else{
st.insert(d[v]);
val[d[v]] = a[v];
}
}
}
void Gold(){
cin >> n >> m;
for(int i = 1 ; i < n ; i++){
int u,v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
for(int i = 1 ; i <= n ; i++) cin >> a[i];
for(int i = 1 ; i <= n ; i++){
st.clear();
ans.clear();
for(int j = 1 ; j <= n ; j++){
d[j] = 0;
ban[j] = 0;
val[j] = 0;
}
dfs(i);
int res = 0;
for(auto it : st){
if(!ban[it]){
ans.insert(val[it]);
}
}
cout << ans.size() << '\n';
}
}
signed main(/*Zhunussov Temirlan*/){
//freopen("txt.in","r",stdin);
//freopen("txt.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
srand(time(0));
int TT = 1;
// cin >> TT;
for(int i = 1 ; i <= TT ; i++){
//cout << "Case " << i << ": ";
Gold();
}
}
Compilation message (stderr)
joi2019_ho_t5.cpp: In function 'void Gold()':
joi2019_ho_t5.cpp:58:7: warning: unused variable 'res' [-Wunused-variable]
58 | int res = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |