#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
using namespace std;
const int MAXN = 200055;
vector<int> G[MAXN];
int A[MAXN], B[MAXN], C[MAXN];
int N, K;
int main() {
ios::sync_with_stdio(false);
cin >> N >> K;
for(int i = 1, a, b; i < N; i++) {
cin >> a >> b;
G[a].eb(b);
G[b].eb(a);
}
for(int i = 1; i <= N; i++) cin >> A[i];
for(int i = 1; i <= N; i++) {
fill(B, B+N+1, N);
queue<int> PQ;
B[i] = 0; PQ.push(i);
for(int idx, day; !PQ.empty();) {
idx = PQ.front(); PQ.pop();
day = B[idx] + 1;
for(int v : G[idx]) {
if(B[v] <= day) continue;
B[v] = day;
PQ.push(v);
}
}
fill(C, C+N+1, 0);
for(int j = 1; j <= N; j++) C[B[j]]++;
vector<int> V;
for(int j = 1; j <= N; j++) if(i != j && 1 == C[B[j]]) V.eb(A[j]);
sorv(V); univ(V);
printf("%d\n", sz(V));
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
67 ms |
5120 KB |
Output is correct |
3 |
Correct |
44 ms |
5120 KB |
Output is correct |
4 |
Correct |
68 ms |
5120 KB |
Output is correct |
5 |
Correct |
82 ms |
5120 KB |
Output is correct |
6 |
Correct |
140 ms |
5200 KB |
Output is correct |
7 |
Correct |
76 ms |
5192 KB |
Output is correct |
8 |
Correct |
55 ms |
5148 KB |
Output is correct |
9 |
Correct |
90 ms |
5240 KB |
Output is correct |
10 |
Correct |
87 ms |
5200 KB |
Output is correct |
11 |
Correct |
87 ms |
5188 KB |
Output is correct |
12 |
Correct |
52 ms |
5120 KB |
Output is correct |
13 |
Correct |
132 ms |
5120 KB |
Output is correct |
14 |
Correct |
86 ms |
5204 KB |
Output is correct |
15 |
Correct |
85 ms |
5240 KB |
Output is correct |
16 |
Correct |
44 ms |
5220 KB |
Output is correct |
17 |
Correct |
92 ms |
5208 KB |
Output is correct |
18 |
Correct |
67 ms |
5200 KB |
Output is correct |
19 |
Correct |
81 ms |
5120 KB |
Output is correct |
20 |
Correct |
186 ms |
5248 KB |
Output is correct |
21 |
Correct |
81 ms |
5200 KB |
Output is correct |
22 |
Correct |
60 ms |
5248 KB |
Output is correct |
23 |
Correct |
96 ms |
5196 KB |
Output is correct |
24 |
Correct |
84 ms |
5196 KB |
Output is correct |
25 |
Correct |
86 ms |
5120 KB |
Output is correct |
26 |
Correct |
58 ms |
5092 KB |
Output is correct |
27 |
Correct |
147 ms |
5208 KB |
Output is correct |
28 |
Correct |
114 ms |
5212 KB |
Output is correct |
29 |
Correct |
79 ms |
5120 KB |
Output is correct |
30 |
Correct |
46 ms |
5204 KB |
Output is correct |
31 |
Correct |
117 ms |
5212 KB |
Output is correct |
32 |
Correct |
75 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2037 ms |
10176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2044 ms |
11896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
67 ms |
5120 KB |
Output is correct |
3 |
Correct |
44 ms |
5120 KB |
Output is correct |
4 |
Correct |
68 ms |
5120 KB |
Output is correct |
5 |
Correct |
82 ms |
5120 KB |
Output is correct |
6 |
Correct |
140 ms |
5200 KB |
Output is correct |
7 |
Correct |
76 ms |
5192 KB |
Output is correct |
8 |
Correct |
55 ms |
5148 KB |
Output is correct |
9 |
Correct |
90 ms |
5240 KB |
Output is correct |
10 |
Correct |
87 ms |
5200 KB |
Output is correct |
11 |
Correct |
87 ms |
5188 KB |
Output is correct |
12 |
Correct |
52 ms |
5120 KB |
Output is correct |
13 |
Correct |
132 ms |
5120 KB |
Output is correct |
14 |
Correct |
86 ms |
5204 KB |
Output is correct |
15 |
Correct |
85 ms |
5240 KB |
Output is correct |
16 |
Correct |
44 ms |
5220 KB |
Output is correct |
17 |
Correct |
92 ms |
5208 KB |
Output is correct |
18 |
Correct |
67 ms |
5200 KB |
Output is correct |
19 |
Correct |
81 ms |
5120 KB |
Output is correct |
20 |
Correct |
186 ms |
5248 KB |
Output is correct |
21 |
Correct |
81 ms |
5200 KB |
Output is correct |
22 |
Correct |
60 ms |
5248 KB |
Output is correct |
23 |
Correct |
96 ms |
5196 KB |
Output is correct |
24 |
Correct |
84 ms |
5196 KB |
Output is correct |
25 |
Correct |
86 ms |
5120 KB |
Output is correct |
26 |
Correct |
58 ms |
5092 KB |
Output is correct |
27 |
Correct |
147 ms |
5208 KB |
Output is correct |
28 |
Correct |
114 ms |
5212 KB |
Output is correct |
29 |
Correct |
79 ms |
5120 KB |
Output is correct |
30 |
Correct |
46 ms |
5204 KB |
Output is correct |
31 |
Correct |
117 ms |
5212 KB |
Output is correct |
32 |
Correct |
75 ms |
5120 KB |
Output is correct |
33 |
Execution timed out |
2037 ms |
10176 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |