#include<algorithm> #include<cassert> #include<cmath> #include<cstdio> #include<cstring> #include<deque> #include<iostream> #include<map> #include<queue> #include<set> #include<stack> #include<string> #include<utility> #include<vector> #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define per(i, l, r) for (int i = (l); i >= (r); --i) using std::cerr; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::pair; typedef pair<int, int> pii; typedeflonglong ll; typedefunsignedint ui;
voidtarjan(int u){ tag[u] = 1; for (auto v : g[u]) { if (tag[v] == 0) { tarjan(v); fa[v] = u; } } for (int i = 0; i < query[u].size(); ++i) { int v = query[u][i]; if (tag[v] == 2) { ans[query_id[u][i]] = get(v); } } tag[u] = 2; }
intmain(){ #ifdef LOCAL freopen("input", "r", stdin); #endif std::ios::sync_with_stdio(false); cout.tie(0); int n, m, s; cin >> n >> m >> s; fa[1] = 1; rep(i, 2, n) { fa[i] = i; int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } rep(i, 1, m) { int u, v; cin >> u >> v; query[u].push_back(v), query_id[u].push_back(i); query[v].push_back(u), query_id[v].push_back(i); } tarjan(s); rep(i, 1, m) cout << ans[i] << endl; return0; }