func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<long long> V[100005];   long long n;   map<long long, long long> DP[100005];   long long concatHash(long long x, long long y) {     return (x * 100005 + y) % 1000000007;   }   void answer(long long x) {     cout << x;     exit(0);   }   void fail() {     cout << -1;     exit(0);   }   void prec(long long x, long long f) {     if (V[x].size() == 1 && f) {       DP[x][f] = 1;       return;     }     unordered_set<long long> S;     for (auto i : V[x]) {       if (i != f) {         prec(i, x);         if (DP[i][x] == -1) DP[x][f] = -1;         S.insert(DP[i][x]);       }     }     if (DP[x][f] == -1) return;     if (S.size() == 1) {       long long chash = *(S.begin());       DP[x][f] = concatHash(chash, V[x].size());     } else       DP[x][f] = -1;   }   void DFS(long long x, long long f, long long phash) {     if (V[x].size() == 1 && f) {       if (phash != -1) {         answer(x);       }       return;     }     unordered_map<long long, long long> S;     for (auto i : V[x])       if (i != f) S[DP[i][x]]++;     if (f) S[phash]++;     if (S.size() == 0) {       assert(false);       return;     }     if (S.size() == 1 && S.begin()->first != -1) {       answer(x);     }     if (S.size() == 1 && S.begin()->first == -1) {       if (S.begin()->second != 1) return;       for (auto i : V[x]) {         if (DP[i][x] == -1) {           if (f)             DFS(i, x, concatHash(phash, V[x].size()));           else             DFS(i, x, V[x].size());           return;         }       }     }     if (S.size() >= 3) {       return;     }     auto it = S.begin();     auto a = make_pair(it->first, it->second);     it++;     auto b = make_pair(it->first, it->second);     for (auto i : V[x]) {       if (i != f && (DP[i][x] == a.first && a.second == 1 && b.first != -1)) {         DFS(i, x, concatHash(b.first, V[x].size()));       }       if (i != f && (DP[i][x] == b.first && b.second == 1 && a.first != -1)) {         DFS(i, x, concatHash(a.first, V[x].size()));       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     if (n == 1) {       answer(1);     }     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       V[x].push_back(y);       V[y].push_back(x);     }     prec(1, 0);     DFS(1, 0, -1);     cout << -1;     return 0;   }   