#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,fma,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 3e3 + 5;
int n, m, d[maxn], c[maxn];
vi g[maxn];
int ans;
void dfs(int v, int p, int dp) {
if(dp) {
if(d[dp]) d[dp]=-1;
else d[dp] = c[v];
}
for(int i : g[v]) if(i!=p) dfs(i, v, dp+1);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int f, t, i = 1; i < n; i++)cin >> f >> t,g[f].pb(t), g[t].pb(f);
for(int i = 1; i <= n; i++) cin >> c[i];
for(int i = 1; i <= n; i++) {
memset(d, 0, sizeof d);
dfs(i, i, 0);
set<int> t;
for(int i = 1; i <= n; i++) if(d[i]>0) t.insert(d[i]);
cout << t.size() << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
55 ms |
504 KB |
Output is correct |
3 |
Correct |
77 ms |
504 KB |
Output is correct |
4 |
Correct |
90 ms |
632 KB |
Output is correct |
5 |
Correct |
67 ms |
632 KB |
Output is correct |
6 |
Correct |
147 ms |
632 KB |
Output is correct |
7 |
Correct |
95 ms |
628 KB |
Output is correct |
8 |
Correct |
56 ms |
504 KB |
Output is correct |
9 |
Correct |
71 ms |
504 KB |
Output is correct |
10 |
Correct |
70 ms |
504 KB |
Output is correct |
11 |
Correct |
68 ms |
504 KB |
Output is correct |
12 |
Correct |
41 ms |
504 KB |
Output is correct |
13 |
Correct |
139 ms |
632 KB |
Output is correct |
14 |
Correct |
88 ms |
632 KB |
Output is correct |
15 |
Correct |
95 ms |
636 KB |
Output is correct |
16 |
Correct |
31 ms |
504 KB |
Output is correct |
17 |
Correct |
94 ms |
632 KB |
Output is correct |
18 |
Correct |
87 ms |
504 KB |
Output is correct |
19 |
Correct |
65 ms |
504 KB |
Output is correct |
20 |
Correct |
367 ms |
760 KB |
Output is correct |
21 |
Correct |
121 ms |
652 KB |
Output is correct |
22 |
Correct |
57 ms |
504 KB |
Output is correct |
23 |
Correct |
83 ms |
504 KB |
Output is correct |
24 |
Correct |
64 ms |
588 KB |
Output is correct |
25 |
Correct |
65 ms |
504 KB |
Output is correct |
26 |
Correct |
43 ms |
508 KB |
Output is correct |
27 |
Correct |
240 ms |
760 KB |
Output is correct |
28 |
Correct |
164 ms |
632 KB |
Output is correct |
29 |
Correct |
95 ms |
632 KB |
Output is correct |
30 |
Correct |
30 ms |
504 KB |
Output is correct |
31 |
Correct |
157 ms |
632 KB |
Output is correct |
32 |
Correct |
114 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
55 ms |
504 KB |
Output is correct |
3 |
Correct |
77 ms |
504 KB |
Output is correct |
4 |
Correct |
90 ms |
632 KB |
Output is correct |
5 |
Correct |
67 ms |
632 KB |
Output is correct |
6 |
Correct |
147 ms |
632 KB |
Output is correct |
7 |
Correct |
95 ms |
628 KB |
Output is correct |
8 |
Correct |
56 ms |
504 KB |
Output is correct |
9 |
Correct |
71 ms |
504 KB |
Output is correct |
10 |
Correct |
70 ms |
504 KB |
Output is correct |
11 |
Correct |
68 ms |
504 KB |
Output is correct |
12 |
Correct |
41 ms |
504 KB |
Output is correct |
13 |
Correct |
139 ms |
632 KB |
Output is correct |
14 |
Correct |
88 ms |
632 KB |
Output is correct |
15 |
Correct |
95 ms |
636 KB |
Output is correct |
16 |
Correct |
31 ms |
504 KB |
Output is correct |
17 |
Correct |
94 ms |
632 KB |
Output is correct |
18 |
Correct |
87 ms |
504 KB |
Output is correct |
19 |
Correct |
65 ms |
504 KB |
Output is correct |
20 |
Correct |
367 ms |
760 KB |
Output is correct |
21 |
Correct |
121 ms |
652 KB |
Output is correct |
22 |
Correct |
57 ms |
504 KB |
Output is correct |
23 |
Correct |
83 ms |
504 KB |
Output is correct |
24 |
Correct |
64 ms |
588 KB |
Output is correct |
25 |
Correct |
65 ms |
504 KB |
Output is correct |
26 |
Correct |
43 ms |
508 KB |
Output is correct |
27 |
Correct |
240 ms |
760 KB |
Output is correct |
28 |
Correct |
164 ms |
632 KB |
Output is correct |
29 |
Correct |
95 ms |
632 KB |
Output is correct |
30 |
Correct |
30 ms |
504 KB |
Output is correct |
31 |
Correct |
157 ms |
632 KB |
Output is correct |
32 |
Correct |
114 ms |
764 KB |
Output is correct |
33 |
Runtime error |
5 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
34 |
Halted |
0 ms |
0 KB |
- |