26 lines
517 B
Python
26 lines
517 B
Python
import sys
|
|
sys.setrecursionlimit(10**6)
|
|
input = sys.stdin.readline
|
|
|
|
N, R, Q = map(int, input().split())
|
|
|
|
edges = [[] for _ in range(N+1)]
|
|
|
|
for _ in range(N-1) :
|
|
u, v = map(int, input().split())
|
|
edges[u].append(v)
|
|
edges[v].append(u)
|
|
|
|
dp = [0]*(N+1)
|
|
|
|
def dfs(current, parent) :
|
|
dp[current] = 1
|
|
|
|
for next in edges[current] :
|
|
if next != parent :
|
|
dfs(next, current)
|
|
dp[current] += dp[next]
|
|
|
|
dfs(R, 0)
|
|
|
|
print("\n".join(map(str, [dp[int(input())] for _ in range(Q)]))) |