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>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;
const int MXN = 2005;
int n, m, dis[MXN][MXN], color[MXN];
vector<int> edge[MXN];
void DFS(int root, int id, int parent, int depth) {
dis[root][id] = depth;
for (auto &i : edge[id]) {
if (i == parent) continue;
DFS(root, i, id, depth + 1);
}
}
int solve(int id) {
int ans = 0;
bitset<MXN> b;
vector<int> v(n, -1);
for (int i = 0; i < n; i++) {
if (i == id) continue;
int &x = v[dis[id][i]];
if (x == -2) continue;
if (x == -1) x = i;
else {
x = -2;
}
}
for (int i = 0; i < n; i++) {
if (v[i] >= 0) {
b[color[v[i]]] = true;
}
}
return b.count();
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int x, y;
cin >> n >> m;
for (int i = 1; i < n; i++) {
cin >> x >> y;
edge[--x].push_back(--y);
edge[y].push_back(x);
}
for (int i = 0; i < n; i++) {
cin >> color[i];
DFS(i, i, -1, 0);
}
for (int i = 0; i < n; i++) cout << solve(i) << endl;
return 0;
}
Compilation message (stderr)
joi2019_ho_t5.cpp: In function 'long long int solve(long long int)':
joi2019_ho_t5.cpp:21:9: warning: unused variable 'ans' [-Wunused-variable]
21 | int ans = 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... |