func_code_string: #include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   template <class T>   void chkmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void chkmin(T &a, T b) {     if (a > b) a = b;   }   const int inf = 0x3f3f3f3f;   const long long linf = 2e18 + 100;   const double dinf = 2e18 + 100;   const double eps = 1e-7;   const double pi = 3.14159265358979323846264338327950288L;   bool scanld(double &first) {     double xx;     int f = scanf( %lf , &xx);     first = xx;     return f > 0;   }   void printld(const double &first) {     printf( %.10lf , fabs(first) < eps ? 0 : (double)first);   }   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   template <class T>   void read(T &first) {     char c = nc(), b = 1;     for (; !((c >=  0  && c <=  9 ) || c == EOF); c = nc())       if (c ==  - ) b = -b;     for (first = 0; c >=  0  && c <=  9 ; first = first * 10 + c -  0 , c = nc())       ;     first *= b;   }   inline void read(char *s) {     char c = nc();     int len = 0;     for (; c ==     || c ==   t  || c ==   n ; c = nc())       ;     for (; !(c ==     || c ==   t  || c ==   n  || c == EOF);          s[len++] = c, c = nc())       ;     s[len] = 0;   }   int n, P[100005], len;   vector<int> v[100005];   int ds[100005];   void dfs(int k, int pa) {     P[k] = pa;     for (auto first : v[k]) {       if (first == pa) continue;       dfs(first, k);     }     return;   }   int mx[100005][3], id[100005][3];   void dfs_2(int k, int pa) {     mx[k][0] = 1, mx[k][1] = 0, mx[k][2] = 0;     id[k][0] = k, id[k][1] = 0, id[k][2] = 0;     for (auto first : v[k]) {       if (first == pa) continue;       dfs_2(first, k);       int d = mx[first][0] + 1;       if (d > mx[k][2]) mx[k][2] = d, id[k][2] = first;       if (mx[k][2] > mx[k][1]) swap(mx[k][1], mx[k][2]), swap(id[k][1], id[k][2]);       if (mx[k][1] > mx[k][0]) swap(mx[k][1], mx[k][0]), swap(id[k][1], id[k][0]);     }     return;   }   bool ok[100005];   int pmx[100005];   void dfs_3(int k, int pa) {     if (!pa)       pmx[k] = 0;     else {       int d = id[pa][0] == k ? mx[pa][1] : mx[pa][0];       chkmax(d, pmx[pa]);       pmx[k] = d + 1;     }     if (mx[k][2] > len || mx[k][1] > len && pmx[k] > len)       ok[k] = 1;     else       ok[k] = 0;     for (auto first : v[k]) {       if (first == pa) continue;       dfs_3(first, k);     }     return;   }   int G, st[100005], fs[100005];   int p[100005][17], dp[100005];   void dfs_4(int k, int pa) {     dp[k] = dp[pa] + 1;     p[k][0] = pa;     st[k] = ++G;     for (int i = 1; i <= 16; i++) p[k][i] = p[p[k][i - 1]][i - 1];     ds[k] = k;     for (auto first : v[k]) {       if (first == pa) continue;       dfs_4(first, k);       if (dp[ds[first]] > dp[ds[k]]) ds[k] = ds[first];     }     fs[k] = ++G;     return;   }   int kth_father(int first, int k) {     for (int i = 16; i >= 0; i--)       if (k & (1 << i)) first = p[first][i];     return first;   }   bool is_anc(int p, int first) {     return st[p] <= st[first] && fs[first] <= fs[p];   }   bool chk[100005];   int head, tail;   int main() {     int T;     for (read(T); T--;) {       read(n);       read(head), read(tail);       int first, second;       for (int i = 1; i < n; i++) {         read(first), read(second);         v[first].push_back(second);         v[second].push_back(first);       }       dfs(head, 0);       len = 0;       int t = tail;       while (t != head) {         len++;         t = P[t];       }       dfs_2(head, 0);       dfs_3(head, 0);       int R = -1;       for (int i = 1; i <= n; i++)         if (ok[i]) R = i;       if (R < 0)         puts( NO );       else {         dfs_4(R, 0);         int dph = dp[head], dpt = dp[tail];         bool yes = is_anc(head, tail) || is_anc(tail, head);         if (!yes) {           int ch = head, ct = tail;           int lca = R;           for (int i = 1; i <= n; i++)             if (is_anc(i, ch) && is_anc(i, ct) && st[i] > st[lca]) lca = i;           int lh = dp[ch] - dp[lca], lt = dp[ct] - dp[lca];           bool fh = 0;           while (!yes) {             if (fh && chk[ch]) break;             if (fh) chk[ch] = 1;             if (fh) {               ch = ds[ch];               if (dp[ch] - dp[lca] >= len)                 yes = 1;               else {                 lh = dp[ch] - dp[lca];                 ct = kth_father(ct, lt - (len - lh));                 lt = dp[ct] - dp[lca];               }             } else {               ct = ds[ct];               if (dp[ct] - dp[lca] >= len)                 yes = 1;               else {                 lt = dp[ct] - dp[lca];                 ch = kth_father(ch, lh - (len - lt));                 lh = dp[ch] - dp[lca];               }             }             fh ^= 1;           }         }         puts(yes ?  YES  :  NO );       }       for (int i = 1; i <= n; i++) v[i].clear();     }     return 0;   }   