-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15681.cpp
43 lines (38 loc) · 802 Bytes
/
15681.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Created by kdongha on 2019/12/26.
//
#include <bits/stdc++.h>
int N, R, Q;
std::vector<int> list[100005];
int size[100005];
int makeTree(int cur, int parent) {
size[cur] = 1;
for (auto child:list[cur]) {
if (child != parent) {
size[cur] += makeTree(child, cur);
}
}
return size[cur];
}
void solve() {
std::cin >> N >> R >> Q;
for (int i = 0; i < N - 1; i++) {
int u, v;
std::cin >> u >> v;
list[u].push_back(v);
list[v].push_back(u);
}
makeTree(R, -1);
for (int i = 0; i < Q; i++) {
int q;
std::cin >> q;
std::cout << size[q] << "\n";
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
solve();
return 0;
}