func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 77;   int T, n, L, R, par[N], fa[N][20];   int dep[N], son[N], tid[N], sz[N];   pair<int, int> mx[N][3];   vector<int> G[N];   void dfs1(int v, int fa) {     mx[v][0] = {0, v}, mx[v][1] = mx[v][2] = {-1, 0};     for (int u : G[v])       if (u ^ fa) {         dfs1(u, v);         pair<int, int> p = {mx[u][0].first + 1, u};         if (p > mx[v][0]) swap(p, mx[v][0]);         if (p > mx[v][1]) swap(p, mx[v][1]);         if (p > mx[v][2]) swap(p, mx[v][2]);       }   };   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d %d %d , &n, &L, &R);       for (int i = 1; i <= n; i++) {         G[i].clear();       }       for (int i = 1, u, v; i < n; i++) {         scanf( %d %d , &u, &v);         G[u].push_back(v), G[v].push_back(u);       }       dfs1(1, 0);       function<void(int, int)> dfs2 = [&](int v, int fa) {         for (int u : G[v])           if (u ^ fa) {             par[u] = max(par[v],                          mx[v][0].second == u ? mx[v][1].first : mx[v][0].first) +                      1,             dfs2(u, v);           }       };       memset(par, 0, sizeof(par)), dfs2(1, 0);       auto find = [&](int u, int v) {         static int dist[N];         fill(dist + 1, dist + n + 1, -1);         queue<int> q;         q.push(u), dist[u] = 0;         while (!q.empty()) {           int x = q.front();           q.pop();           for (int y : G[x])             if (!~dist[y]) {               q.push(y), dist[y] = dist[x] + 1;             }         }         return dist[v];       };       int rt = -1, len = find(L, R);       for (int i = 1; i <= n; i++) {         int cnt = 0;         if (mx[i][0].first >= len) cnt++;         if (mx[i][1].first >= len) cnt++;         if (mx[i][2].first >= len) cnt++;         if (par[i] >= len) cnt++;         if (cnt >= 3) {           rt = i;           break;         }       }       if (!~rt) {         printf( NO n );         continue;       }       int tim = 0;       function<void(int)> dfs3 = [&](int v) {         son[v] = v, tid[v] = ++tim, sz[v] = 1;         for (int i = 1; i < 20; i++) {           fa[v][i] = fa[fa[v][i - 1]][i - 1];         }         for (int u : G[v])           if (u ^ fa[v][0]) {             fa[u][0] = v, dep[u] = dep[v] + 1;             dfs3(u), sz[v] += sz[u];             if (dep[son[u]] > dep[son[v]]) son[v] = son[u];           }       };       fa[rt][0] = rt, dep[rt] = 0, dfs3(rt);       bool flag = 0;       for (int t = 1; t <= n; t++) {         auto chk = [&](int u, int v) {           return tid[v] >= tid[u] && tid[v] < tid[u] + sz[u];         };         if (chk(L, R) || chk(R, L)) {           flag = 1;           break;         }         auto get = [&](int v, int k) {           for (int i = 19; ~i; i--) {             if (k >> i & 1) v = fa[v][i];           }           return v;         };         int num = dep[son[L]] - dep[L];         L = son[L], R = get(R, num), swap(L, R);       }       printf( %s n , flag ?  YES  :  NO );     }     return 0;   }   