#include <bits/stdc++.h>
using namespace std;
int n,m,k,x,y,z;
int c[2005], v[2005], d[2005], ok[2005];
vector<int> gph[2005];
void dfs(int id, int dis) {
v[id] = 1;
d[id] = dis;
for (auto i : gph[id]) {
if (!v[i]) dfs(i,dis+1);
}
}
int main() {
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i < n; i++) {
cin >> x >> y;
gph[x].push_back(y);
gph[y].push_back(x);
}
for (int i = 1; i <= n; i++) cin >> c[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) v[j] = ok[j] = 0;
dfs(i,0);
pair<int,int> ar[2005];
for (int j = 1; j <= n; j++) ar[j] = {d[j],j};
sort(ar+1,ar+1+n);
int ans = 0;
for (int j = 1; j <= n; j++) if (ar[j].first != ar[j-1].first && ar[j].first != ar[j+1].first) {
ok[c[ar[j].second]] = 1;
}
for (int j = 1; j <= n; j++) ans += ok[j];
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
292 ms |
484 KB |
Output is correct |
3 |
Correct |
63 ms |
468 KB |
Output is correct |
4 |
Correct |
262 ms |
524 KB |
Output is correct |
5 |
Correct |
340 ms |
468 KB |
Output is correct |
6 |
Correct |
307 ms |
576 KB |
Output is correct |
7 |
Correct |
318 ms |
540 KB |
Output is correct |
8 |
Correct |
317 ms |
500 KB |
Output is correct |
9 |
Correct |
354 ms |
468 KB |
Output is correct |
10 |
Correct |
358 ms |
496 KB |
Output is correct |
11 |
Correct |
349 ms |
468 KB |
Output is correct |
12 |
Correct |
155 ms |
588 KB |
Output is correct |
13 |
Correct |
318 ms |
572 KB |
Output is correct |
14 |
Correct |
334 ms |
468 KB |
Output is correct |
15 |
Correct |
328 ms |
516 KB |
Output is correct |
16 |
Correct |
84 ms |
468 KB |
Output is correct |
17 |
Correct |
279 ms |
544 KB |
Output is correct |
18 |
Correct |
304 ms |
716 KB |
Output is correct |
19 |
Correct |
338 ms |
468 KB |
Output is correct |
20 |
Correct |
296 ms |
588 KB |
Output is correct |
21 |
Correct |
321 ms |
532 KB |
Output is correct |
22 |
Correct |
332 ms |
484 KB |
Output is correct |
23 |
Correct |
352 ms |
496 KB |
Output is correct |
24 |
Correct |
345 ms |
588 KB |
Output is correct |
25 |
Correct |
355 ms |
488 KB |
Output is correct |
26 |
Correct |
161 ms |
468 KB |
Output is correct |
27 |
Correct |
323 ms |
552 KB |
Output is correct |
28 |
Correct |
298 ms |
716 KB |
Output is correct |
29 |
Correct |
318 ms |
656 KB |
Output is correct |
30 |
Correct |
99 ms |
468 KB |
Output is correct |
31 |
Correct |
284 ms |
552 KB |
Output is correct |
32 |
Correct |
298 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
528 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
292 ms |
484 KB |
Output is correct |
3 |
Correct |
63 ms |
468 KB |
Output is correct |
4 |
Correct |
262 ms |
524 KB |
Output is correct |
5 |
Correct |
340 ms |
468 KB |
Output is correct |
6 |
Correct |
307 ms |
576 KB |
Output is correct |
7 |
Correct |
318 ms |
540 KB |
Output is correct |
8 |
Correct |
317 ms |
500 KB |
Output is correct |
9 |
Correct |
354 ms |
468 KB |
Output is correct |
10 |
Correct |
358 ms |
496 KB |
Output is correct |
11 |
Correct |
349 ms |
468 KB |
Output is correct |
12 |
Correct |
155 ms |
588 KB |
Output is correct |
13 |
Correct |
318 ms |
572 KB |
Output is correct |
14 |
Correct |
334 ms |
468 KB |
Output is correct |
15 |
Correct |
328 ms |
516 KB |
Output is correct |
16 |
Correct |
84 ms |
468 KB |
Output is correct |
17 |
Correct |
279 ms |
544 KB |
Output is correct |
18 |
Correct |
304 ms |
716 KB |
Output is correct |
19 |
Correct |
338 ms |
468 KB |
Output is correct |
20 |
Correct |
296 ms |
588 KB |
Output is correct |
21 |
Correct |
321 ms |
532 KB |
Output is correct |
22 |
Correct |
332 ms |
484 KB |
Output is correct |
23 |
Correct |
352 ms |
496 KB |
Output is correct |
24 |
Correct |
345 ms |
588 KB |
Output is correct |
25 |
Correct |
355 ms |
488 KB |
Output is correct |
26 |
Correct |
161 ms |
468 KB |
Output is correct |
27 |
Correct |
323 ms |
552 KB |
Output is correct |
28 |
Correct |
298 ms |
716 KB |
Output is correct |
29 |
Correct |
318 ms |
656 KB |
Output is correct |
30 |
Correct |
99 ms |
468 KB |
Output is correct |
31 |
Correct |
284 ms |
552 KB |
Output is correct |
32 |
Correct |
298 ms |
592 KB |
Output is correct |
33 |
Runtime error |
1 ms |
528 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |