func_code_string: #include <bits/stdc++.h>   using namespace std;   int n;   int head[100010], to[200010], nxt[200010], cnt, d[100010];   inline void AddEdge(int u, int v) {     ++cnt, to[cnt] = v, nxt[cnt] = head[u], head[u] = cnt;   }   int mxd, mxu, f[100010];   inline void Find(int u, int p, int d) {     if (d > mxd) mxd = d, mxu = u;     f[u] = p;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       Find(v, u, d + 1);     }   }   int depnum[100010];   inline int Checkl(int u, int p) {     if (d[u] > 2) return 0;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       return Checkl(v, u);     }     return u;   }   inline bool Dfs(int u, int p, int dep) {     if (!depnum[dep] || depnum[dep] == d[u])       depnum[dep] = d[u];     else       return false;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       if (!Dfs(v, u, dep + 1)) return false;     }     return true;   }   inline void Check(int u) {     memset(depnum, 0, sizeof(depnum));     for (int e = head[u]; e; e = nxt[e])       if (!Dfs(to[e], u, 1)) return;     printf( %d n , u);     exit(0);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       AddEdge(u, v), AddEdge(v, u);       ++d[u], ++d[v];     }     mxd = -1, Find(1, 0, 0);     int xxu = mxu;     mxd = -1, Find(mxu, 0, 0);     if (mxd & 1) {       Check(xxu), Check(mxu), printf( -1 n );       return 0;     }     for (int i = 1; i <= mxd / 2; ++i) mxu = f[mxu];     for (int e = head[mxu]; e; e = nxt[e])       if (!Checkl(to[e], mxu) && !Dfs(to[e], mxu, 1)) {         printf( -1 n );         return 0;       }     for (int e = head[mxu], l = 0; e; e = nxt[e]) {       int u = Checkl(to[e], mxu);       if (!u) continue;       if (!Dfs(to[e], mxu, 1)) {         if (l) Check(l);         Check(u), printf( -1 n );         return 0;       }       l = u;     }     printf( %d n , mxu);     return 0;   }   