#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct modint {     int n;     modint() : n(0) {}     modint(int n) : n(n) {}   };   modint operator+(modint a, modint b) {     return modint((a.n += b.n) >= mod ? a.n - mod : a.n);   }   modint operator*(modint a, modint b) { return modint(1LL * a.n * b.n % mod); }   bool operator<(modint a, modint b) { return a.n < b.n; }   bool operator!=(modint a, modint b) { return a.n != b.n; }   const int S = 4;   using modints = array<modint, S>;   modints operator+(modints a, modints b) {     modints ret;     for (int i = 0; i < S; i++) {       ret[i] = a[i] + b[i];     }     return ret;   }   modints operator*(modints a, modints b) {     modints ret;     for (int i = 0; i < S; i++) {       ret[i] = a[i] * b[i];     }     return ret;   }   bool operator<(modints a, modints b) {     for (int i = 0; i < S; i++) {       if (a[i] != b[i]) return a[i] < b[i];     }     return false;   }   const int N = 1e5;   int n;   vector<int> g[N];   vector<int> gg[N];   modints rnd[N];   int height[N];   vector<int> h;   modints val[N];   modints one;   map<modints, int> mp;   pair<int, int> ans;   int cnt = 0;   void add(modints a) {     if (mp[a]++ == 0) {       cnt++;     }   }   void del(modints a) {     if (mp[a]-- == 1) {       cnt--;     }     assert(mp[a] >= 0);   }   void dfs(int u, int p) {     for (int v : g[u])       if (v != p) {         dfs(v, u);         height[u] = max(height[u], height[v] + 1);       }     val[u] = one;     for (int v : g[u])       if (v != p) {         val[u] = val[u] * (rnd[height[u]] + val[v]);       }     add(val[u]);   }   void dfs2(int u, int p) {     auto tmp = val[u];     del(tmp);     int n = g[u].size();     h.clear();     h.push_back(0);     for (int v : g[u]) {       h.push_back(height[v] + 1);     }     sort(h.rbegin(), h.rend());     int h0 = h[0];     int h1 = h[1];     modints L0 = one;     modints L1 = one;     vector<modints> R0(n);     vector<modints> R1(n);     R0[n - 1] = one;     R1[n - 1] = one;     for (int i = n - 2; i >= 0; i--) {       R0[i] = R0[i + 1] * (rnd[h0] + val[g[u][i + 1]]);       R1[i] = R1[i + 1] * (rnd[h1] + val[g[u][i + 1]]);     }     ans = max(ans, make_pair(cnt, u));     for (int i = 0; i < n; i++) {       int v = g[u][i];       if (height[v] + 1 != h0) {         height[u] = h0;         val[u] = L0 * R0[i];       } else {         height[u] = h1;         val[u] = L1 * R1[i];       }       L0 = L0 * (rnd[h0] + val[v]);       L1 = L1 * (rnd[h1] + val[v]);       if (v == p) continue;       add(val[u]);       dfs2(v, u);       del(val[u]);     }     add(tmp);   }   int main() {     mt19937 mt(time(NULL) ^ 1234567);     uniform_int_distribution<int> uni(0, mod - 1);     for (int i = 0; i < N; i++) {       for (int j = 0; j < S; j++) {         rnd[i][j] = uni(mt);       }     }     for (int i = 0; i < S; i++) {       one[i] = 1;     }     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     if (n == 1) {       cout << 1 << endl;       return 0;     }     dfs(0, -1);     dfs2(0, -1);     cout << ans.second + 1 << endl;   }