func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const long long mod = (long long)1e9 + 7;   const double eps = (double)1e-9;   const double pi = acos(-1.0);   const int dx[] = {0, 0, 1, 0, -1};   const int dy[] = {0, 1, 0, -1, 0};   const int N = 300500;   int n, dp[N];   vector<int> g[N], l;   vector<pair<int, int> > gr, G, ga[N];   void dfs(int v, int pr = -1) {     dp[v] = 1;     for (int to : g[v]) {       if (to != pr) {         dfs(to, v);         dp[v] += dp[to];       }     }   }   int dfs1(int v) {     for (int to : g[v]) {       if (dp[to] * 2 > n) {         dp[v] -= dp[to];         dp[to] += dp[v];         return dfs1(to);       }     }     return v;   }   void dfs2(int v, int pr, int gl = 0) {     gr.push_back(make_pair(gl, v));     for (int to : g[v]) {       if (to != pr) {         dfs2(to, v, gl + 1);       }     }   }   void checkv(int st) {     gr.clear();     dfs2(st, -1, 0);     sort(gr.begin(), gr.end());     for (int i = 0; i + 1 < n; ++i) {       if (gr[i].first == gr[i + 1].first &&           (int)g[gr[i].second].size() != (int)g[gr[i + 1].second].size())         return;     }     cout << st << endl;     exit(0);   }   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i < n; ++i) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1);     int centroid = dfs1(1);     checkv(centroid);     for (int i = 1; i <= n; ++i)       if ((int)g[i].size() == 1) l.push_back(i);     for (int x : l) {       int last = x;       int cur = g[x][0];       int dist = 1;       while ((int)g[cur].size() == 2) {         int nxt = g[cur][0];         if (nxt == last) nxt = g[cur][1];         dist++;         last = cur;         cur = nxt;       }       if (dist == n - 1) {         checkv(x);         cout << -1;         return 0;       }       ga[cur].push_back(make_pair(x, dist));       G.push_back(make_pair(dist, x));     }     for (int i = 1; i <= n; ++i) {       if ((int)ga[i].size() == 1) {         checkv(ga[i][0].first);         cout << -1;         return 0;       }     }     for (int i = 0; i + 1 < (int)G.size(); ++i)       if (G[i].first != G[i + 1].first) {         checkv(G[i].second);         checkv(G[i + 1].second);         cout << -1;         return 0;       }     cout << -1 << endl;     return 0;     return 0;   }   