func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<int> e[200010];   vector<int> a;   int n;   int siz[200010];   int id[200010];   int d[200010];   int c[200010];   int f[200010];   int dfn;   void dfs(int x, int fa) {     id[x] = ++dfn;     siz[x]++;     for (int i = 0; i < e[x].size(); i++) {       if (e[x][i] == fa) continue;       dfs(e[x][i], x);       siz[x] += siz[e[x][i]];     }   }   void dfs(int x, int fa, int *y) {     int temp = (n - siz[x]);     bool flag = true;     for (int i = 0; i < e[x].size(); i++) {       if (e[x][i] == fa) continue;       dfs(e[x][i], x, y);       if (temp != siz[e[x][i]]) {         flag = false;       }     }     if (flag && siz[x] > 1) {       *y = x;     }   }   bool judge(int x, int fa, int dep) {     if (c[x] != -1 && f[x] != fa && c[x] != fa) return false;     f[x] = -1;     for (int i = 0; i < e[x].size(); i++) {       int nt = e[x][i];       if (nt == fa) continue;       int son_siz = siz[nt];       if (id[x] > id[nt]) son_siz = n - siz[x];       if (d[dep] == -1) {         d[dep] = son_siz;       }       if (d[dep] != son_siz) {         c[x] = nt;         return false;       }       f[x] = nt;     }     for (int i = 0; i < e[x].size(); i++) {       int nt = e[x][i];       if (nt == fa) continue;       if (!judge(nt, x, dep + 1)) {         c[x] = nt;         return false;       }       f[x] = nt;     }     f[x] = -1;     return true;   }   inline bool scan_d(int &num) {     char in;     bool IsN = false;     in = getchar();     if (in == EOF) return false;     while (in !=  -  && (in <  0  || in >  9 )) in = getchar();     if (in ==  - ) {       IsN = true;       num = 0;     } else       num = in -  0 ;     while (in = getchar(), in >=  0  && in <=  9 ) {       num *= 10, num += in -  0 ;     }     if (IsN) num = -num;     return true;   }   int main() {     int x = -1, u, v, k = -1;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scan_d(u);       scan_d(v);       if (k == -1) k = u;       e[u].push_back(v);       e[v].push_back(u);     }     dfs(1, 1);     dfs(1, 1, &x);     for (int i = 1; i <= n; i++) {       if (e[i].size() <= 1) {         a.push_back(i);       }     }     if (x != -1) {       a.push_back(x);     }     memset(d, -1, sizeof(d));     memset(c, -1, sizeof(c));     memset(f, -1, sizeof(f));     for (int i = 0; i < a.size(); i++) {       if (judge(a[i], a[i], 1)) {         printf( %d n , a[i]);         return 0;       }       for (int i = 1;; i++) {         if (d[i] == -1) break;         d[i] = -1;       }     }     printf( -1 n );     return 0;   }   