# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99717 | cki86201 | Unique Cities (JOI19_ho_t5) | C++11 | 130 ms | 16460 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;
int N, M;
vector <int> E[2020];
int C[2020];
int dis[2020][2020];
int main() {
scanf("%d%d", &N, &M);
if(N > 2000) return 0;
for(int i=1;i<N;i++) {
int x, y; scanf("%d%d", &x, &y);
E[x].pb(y); E[y].pb(x);
}
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++) dis[i][j] = -1;
dis[i][i] = 0;
vector <int> q;
q.pb(i);
rep(a, szz(q)) {
int t = q[a];
for(int e : E[t]) if(dis[i][e] == -1) {
dis[i][e] = dis[i][t] + 1;
q.pb(e);
}
}
int cnt[2020] = {}, er[2020] = {};
for(int j=1;j<=N;j++) cnt[dis[i][j]]++;
int ans = 0;
for(int j=1;j<=N;j++) if(j != i && cnt[dis[i][j]] == 1) {
if(er[C[j]] == 0) er[C[j]] = 1, ++ans;
}
printf("%d\n", ans);
}
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... |