diff --git "a/12_\355\212\270\353\246\254/\355\225\204\354\210\230/BOJ_15681.cpp" "b/12_\355\212\270\353\246\254/\355\225\204\354\210\230/BOJ_15681.cpp" new file mode 100644 index 00000000..5ca9379e --- /dev/null +++ "b/12_\355\212\270\353\246\254/\355\225\204\354\210\230/BOJ_15681.cpp" @@ -0,0 +1,59 @@ +#include +#include +#include + +using namespace std; + +map> tree; +vector edge_v[100001]; +int nodeSize[100001]; + +void makeTree(int current, int parent) { + for (int node : edge_v[current]) { + if (node != parent) { + tree[current].push_back(node); + makeTree(node, current); + } + } + return; +} + +void countNode(int node) { + nodeSize[node] = 1; + + for (int child : tree[node]) { + countNode(child); + nodeSize[node] += nodeSize[child]; + } + return; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + // 입력 + int n, r, q, root; + cin >> n >> r >> q; + + int c = (n - 1); + int i, j; + while (c--) { + cin >> i >> j; + edge_v[i].push_back(j); + edge_v[j].push_back(i); + } + + // 연산 + makeTree(r, -1); + countNode(r); + + // 출력 + for (int i = 0; i < q; i++) { + cin >> root; + cout << nodeSize[root] << '\n'; + } + + return 0; +} \ No newline at end of file