# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
202613 | dndhk | Unique Cities (JOI19_ho_t5) | C++14 | 2037 ms | 16120 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 200000;
int N, M;
int c[MAX_N+1];
vector<int> gp[MAX_N+1];
int vst[MAX_N+1];
int lv[MAX_N+1], p[MAX_N+1];
int cnt[MAX_N+1];
set<int> st;
void dfs(int x){
cnt[lv[x]]++;
for(int i : gp[x]){
if(i==p[x]) continue;
p[i] = x;
lv[i] = lv[x]+1;
dfs(i);
}
}
int main(){
scanf("%d%d", &N, &M);
for(int i=1; i<N; i++){
int a, b; scanf("%d%d", &a, &b);
gp[a].pb(b); gp[b].pb(a);
}
for(int i=1; i<=N; i++){
scanf("%d", &c[i]);
}
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++) cnt[j] = vst[j] = lv[j] = p[j] = 0;
lv[i] = 1; dfs(i);
st.clear();
for(int j=1; j<=N; j++){
if(i==j) continue;
if(cnt[lv[j]]==1){
st.insert(c[j]);
}
}
printf("%d\n", (int)st.size());
}
return 0;
}
Compilation message (stderr)
# | 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... |