func_code_string: #include <bits/stdc++.h>   const int mod = 1000000007;   const int inf = 1000000009;   const long long int INF = 1000000000000000009;   const long long big = 1000000000000000;   const long double eps = 0.0000000001;   using namespace std;   queue<int> K;   vector<int> H;   vector<int> P[100005];   int S[100005], G[100005];   int k;   bool czy = true, jak = false, korzen = false;   map<int, int> M;   int L[100005];   int n;   void check(int u, int p) {     if (M[L[u]] && P[u].size() != M[L[u]]) jak = false;     M[L[u]] = P[u].size();     for (auto v : P[u])       if (v != p) {         L[v] = L[u] + 1;         check(v, u);       }   }   void czysc() {     for (int i = 1; i <= n; i++) {       L[i] = 0;       M[i] = 0;     }   }   void funkcja() {     while (K.size()) {       if (K.size() == 1) korzen = true;       while (K.size()) {         int u = K.front();         K.pop();         for (auto v : P[u]) {           if (!S[v]) {             S[v] = S[u];             H.push_back(v);           }           G[v]++;         }       }       int ile = -1, ile2 = -1, skad;       for (auto v : H) {         if (ile == -1) {           ile = G[v];           ile2 = P[v].size();           skad = v;         } else if (ile != G[v] || ile2 != P[v].size()) {           czy = false;           jak = true;           k = v;           check(S[v], 0);           czysc();           if (!jak) {             k = skad;             check(S[skad], 0);             czysc();           }           return;         }         K.push(v);         k = v;       }       H.clear();     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       P[a].push_back(b);       P[b].push_back(a);     }     for (int i = 1; i <= n; i++)       if (P[i].size() == 1) {         K.push(i);         S[i] = i;       }     funkcja();     if (!korzen) {       jak = true;       check(S[k], 0);       k = S[k];     }     jak = true;     check(k, 0);     if (jak)       cout << k;     else       cout << -1;     return 0;   }   