#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) begin(x), end(x)
#define kill(x) return cout << x << '\n', 0
#define fst first
#define snd second
void assume(int expr) {
if (!expr) __builtin_unreachable();
}
constexpr int N = 2e3 + 10;
constexpr int MOD = 1e9 + 7;
int n, m, C[N];
vector<int> adj[N];
vector<int> H[N];
void dfs(int u, int p, int h) {
H[h].push_back(u);
for (int v : adj[u]) if (v != p)
dfs(v, u, h+1);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < n-1; i++) {
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; i++) {
cin >> C[i];
}
for (int i = 1; i <= n; i++) {
dfs(i, 0, 0);
set<int> st;
for (int j = 1; j <= n; j++) {
if (H[j].size() == 1)
st.insert(C[H[j][0]]);
H[j].clear();
}
cout << st.size() << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
52 ms |
596 KB |
Output is correct |
3 |
Correct |
54 ms |
564 KB |
Output is correct |
4 |
Correct |
75 ms |
704 KB |
Output is correct |
5 |
Correct |
59 ms |
556 KB |
Output is correct |
6 |
Correct |
111 ms |
684 KB |
Output is correct |
7 |
Correct |
82 ms |
660 KB |
Output is correct |
8 |
Correct |
56 ms |
548 KB |
Output is correct |
9 |
Correct |
65 ms |
460 KB |
Output is correct |
10 |
Correct |
61 ms |
688 KB |
Output is correct |
11 |
Correct |
68 ms |
552 KB |
Output is correct |
12 |
Correct |
39 ms |
556 KB |
Output is correct |
13 |
Correct |
112 ms |
796 KB |
Output is correct |
14 |
Correct |
67 ms |
1432 KB |
Output is correct |
15 |
Correct |
71 ms |
1208 KB |
Output is correct |
16 |
Correct |
28 ms |
540 KB |
Output is correct |
17 |
Correct |
77 ms |
3180 KB |
Output is correct |
18 |
Correct |
72 ms |
1580 KB |
Output is correct |
19 |
Correct |
59 ms |
460 KB |
Output is correct |
20 |
Correct |
260 ms |
748 KB |
Output is correct |
21 |
Correct |
102 ms |
848 KB |
Output is correct |
22 |
Correct |
56 ms |
556 KB |
Output is correct |
23 |
Correct |
63 ms |
588 KB |
Output is correct |
24 |
Correct |
60 ms |
588 KB |
Output is correct |
25 |
Correct |
65 ms |
576 KB |
Output is correct |
26 |
Correct |
43 ms |
460 KB |
Output is correct |
27 |
Correct |
186 ms |
692 KB |
Output is correct |
28 |
Correct |
149 ms |
3012 KB |
Output is correct |
29 |
Correct |
84 ms |
1384 KB |
Output is correct |
30 |
Correct |
29 ms |
460 KB |
Output is correct |
31 |
Correct |
125 ms |
3284 KB |
Output is correct |
32 |
Correct |
90 ms |
1488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
676 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
52 ms |
596 KB |
Output is correct |
3 |
Correct |
54 ms |
564 KB |
Output is correct |
4 |
Correct |
75 ms |
704 KB |
Output is correct |
5 |
Correct |
59 ms |
556 KB |
Output is correct |
6 |
Correct |
111 ms |
684 KB |
Output is correct |
7 |
Correct |
82 ms |
660 KB |
Output is correct |
8 |
Correct |
56 ms |
548 KB |
Output is correct |
9 |
Correct |
65 ms |
460 KB |
Output is correct |
10 |
Correct |
61 ms |
688 KB |
Output is correct |
11 |
Correct |
68 ms |
552 KB |
Output is correct |
12 |
Correct |
39 ms |
556 KB |
Output is correct |
13 |
Correct |
112 ms |
796 KB |
Output is correct |
14 |
Correct |
67 ms |
1432 KB |
Output is correct |
15 |
Correct |
71 ms |
1208 KB |
Output is correct |
16 |
Correct |
28 ms |
540 KB |
Output is correct |
17 |
Correct |
77 ms |
3180 KB |
Output is correct |
18 |
Correct |
72 ms |
1580 KB |
Output is correct |
19 |
Correct |
59 ms |
460 KB |
Output is correct |
20 |
Correct |
260 ms |
748 KB |
Output is correct |
21 |
Correct |
102 ms |
848 KB |
Output is correct |
22 |
Correct |
56 ms |
556 KB |
Output is correct |
23 |
Correct |
63 ms |
588 KB |
Output is correct |
24 |
Correct |
60 ms |
588 KB |
Output is correct |
25 |
Correct |
65 ms |
576 KB |
Output is correct |
26 |
Correct |
43 ms |
460 KB |
Output is correct |
27 |
Correct |
186 ms |
692 KB |
Output is correct |
28 |
Correct |
149 ms |
3012 KB |
Output is correct |
29 |
Correct |
84 ms |
1384 KB |
Output is correct |
30 |
Correct |
29 ms |
460 KB |
Output is correct |
31 |
Correct |
125 ms |
3284 KB |
Output is correct |
32 |
Correct |
90 ms |
1488 KB |
Output is correct |
33 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |