#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false), cin.tie(0)
#endif
const int N = 2001;
vector <int> adj[N];
vector <int> f[N];
void dfs(int v, int pa, int d = 0) {
f[d].pb(v);
for (int u : adj[v]) if (u != pa) {
dfs(u, v, d + 1);
}
}
int main () {
owo;
int n, m;
cin >> n >> m;
for (int i = 0, u, v; i < n - 1; ++i) {
cin >> u >> v, --u, --v;
adj[u].pb(v), adj[v].pb(u);
}
vector <int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i) {
for (int i = 0; i <= n; ++i)
f[i].clear();
dfs(i, -1);
set <int> S;
for (int i = 1; i <= n; ++i) {
if (f[i].size() == 1)
S.insert(a[f[i][0]]);
}
cout << S.size() << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
60 ms |
536 KB |
Output is correct |
3 |
Correct |
70 ms |
548 KB |
Output is correct |
4 |
Correct |
84 ms |
704 KB |
Output is correct |
5 |
Correct |
64 ms |
536 KB |
Output is correct |
6 |
Correct |
130 ms |
792 KB |
Output is correct |
7 |
Correct |
100 ms |
668 KB |
Output is correct |
8 |
Correct |
70 ms |
540 KB |
Output is correct |
9 |
Correct |
69 ms |
552 KB |
Output is correct |
10 |
Correct |
65 ms |
660 KB |
Output is correct |
11 |
Correct |
66 ms |
472 KB |
Output is correct |
12 |
Correct |
41 ms |
592 KB |
Output is correct |
13 |
Correct |
116 ms |
720 KB |
Output is correct |
14 |
Correct |
76 ms |
1348 KB |
Output is correct |
15 |
Correct |
89 ms |
1224 KB |
Output is correct |
16 |
Correct |
31 ms |
424 KB |
Output is correct |
17 |
Correct |
91 ms |
3288 KB |
Output is correct |
18 |
Correct |
87 ms |
1556 KB |
Output is correct |
19 |
Correct |
63 ms |
544 KB |
Output is correct |
20 |
Correct |
266 ms |
732 KB |
Output is correct |
21 |
Correct |
100 ms |
748 KB |
Output is correct |
22 |
Correct |
62 ms |
544 KB |
Output is correct |
23 |
Correct |
71 ms |
572 KB |
Output is correct |
24 |
Correct |
63 ms |
584 KB |
Output is correct |
25 |
Correct |
63 ms |
552 KB |
Output is correct |
26 |
Correct |
43 ms |
556 KB |
Output is correct |
27 |
Correct |
202 ms |
828 KB |
Output is correct |
28 |
Correct |
154 ms |
3120 KB |
Output is correct |
29 |
Correct |
88 ms |
1352 KB |
Output is correct |
30 |
Correct |
32 ms |
536 KB |
Output is correct |
31 |
Correct |
126 ms |
3232 KB |
Output is correct |
32 |
Correct |
95 ms |
1660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
668 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
704 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
60 ms |
536 KB |
Output is correct |
3 |
Correct |
70 ms |
548 KB |
Output is correct |
4 |
Correct |
84 ms |
704 KB |
Output is correct |
5 |
Correct |
64 ms |
536 KB |
Output is correct |
6 |
Correct |
130 ms |
792 KB |
Output is correct |
7 |
Correct |
100 ms |
668 KB |
Output is correct |
8 |
Correct |
70 ms |
540 KB |
Output is correct |
9 |
Correct |
69 ms |
552 KB |
Output is correct |
10 |
Correct |
65 ms |
660 KB |
Output is correct |
11 |
Correct |
66 ms |
472 KB |
Output is correct |
12 |
Correct |
41 ms |
592 KB |
Output is correct |
13 |
Correct |
116 ms |
720 KB |
Output is correct |
14 |
Correct |
76 ms |
1348 KB |
Output is correct |
15 |
Correct |
89 ms |
1224 KB |
Output is correct |
16 |
Correct |
31 ms |
424 KB |
Output is correct |
17 |
Correct |
91 ms |
3288 KB |
Output is correct |
18 |
Correct |
87 ms |
1556 KB |
Output is correct |
19 |
Correct |
63 ms |
544 KB |
Output is correct |
20 |
Correct |
266 ms |
732 KB |
Output is correct |
21 |
Correct |
100 ms |
748 KB |
Output is correct |
22 |
Correct |
62 ms |
544 KB |
Output is correct |
23 |
Correct |
71 ms |
572 KB |
Output is correct |
24 |
Correct |
63 ms |
584 KB |
Output is correct |
25 |
Correct |
63 ms |
552 KB |
Output is correct |
26 |
Correct |
43 ms |
556 KB |
Output is correct |
27 |
Correct |
202 ms |
828 KB |
Output is correct |
28 |
Correct |
154 ms |
3120 KB |
Output is correct |
29 |
Correct |
88 ms |
1352 KB |
Output is correct |
30 |
Correct |
32 ms |
536 KB |
Output is correct |
31 |
Correct |
126 ms |
3232 KB |
Output is correct |
32 |
Correct |
95 ms |
1660 KB |
Output is correct |
33 |
Runtime error |
1 ms |
668 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |