#include <iostream>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <iomanip>
#include <queue>
#include <utility>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pci;
typedef pair<bool, int> pbi;
typedef pair<ll, int> pli;

const int kN = 100 * 1000;
const int kM = 2 * kN + 1;
const ll kMod = 18014398241046527LL;
const ll kBase = 3;

vector<int> g[kN];
ll pow_base[kM];
ll h[kN];
int sz[kN];
map<ll, int> cnt;

ll Add(ll a, ll b) {
    // assert(a >= 0 && b >= 0);
    ll res = a + b;
    return res < kMod ? res : res - kMod;
}

ll Sub(ll a, ll b) {
    // assert(a >= 0 && b >= 0);
    ll res = a - b;
    return res < 0 ? res + kMod : res;
}

ll Mul(ll a, ll b) {
    // assert(a >= 0 && b >= 0);
    ll res = 0;
    ll carry = a;
    while (b) {
        if (b & 1) {
            res = Add(res, carry);
        }
        carry = Add(carry, carry);
        b >>= 1;
    }
    return res;
}

ll GetHash(const vector<pli>& items) {
    ll hh = 1;
    for (const auto& item : items) {
        hh = Add(Mul(hh, pow_base[item.second]), item.first);
    }
    hh = Add(Mul(hh, kBase), 2);
    return hh;
}

void DfsHash(int u, int p = -1) {
    vector<pli> items;
    sz[u] = 1;
    for (int v : g[u]) {
        if (v == p) { continue; }
        DfsHash(v, u);
        sz[u] += sz[v];
        items.emplace_back(h[v], 2 * sz[v]);
    }
    sort(items.begin(), items.end());
    h[u] = GetHash(items);
}

struct Node {
    map<ll, int> cnt;
    int res;

    Node() : res(0) {}

    void Insert(ll h) {
        ll val = ++cnt[h];
        if (val == 1) { ++res; }
        if (val == 2) { --res; }
    }

    void Erase(ll h) {
        auto it = cnt.find(h);
        // assert(it != cnt.end());
        --(it->second);
        if (it->second == 1) { ++res; }
        if (it->second == 0) { --res; cnt.erase(it); }
    }
};

Node node;
int best = -1, vert = -1;

void Dfs(int u, int p = -1, ll uph = 0, ll szp = 0) {
    vector<tuple<ll, int, int>> items = {make_tuple(uph, 2 * szp, p)};
    for (int v : g[u]) {
        if (v == p) { continue; }
        items.emplace_back(h[v], 2 * sz[v], v);
    }
    sort(items.begin(), items.end());
    vector<ll> pref = {0, 1};
    vector<int> pref_size = {0, 1};
    for (const auto& item : items) {
        pref.push_back(Add(Mul(pref.back(), pow_base[get<1>(item)]), get<0>(item)));
        pref_size.push_back(pref_size.back() + get<1>(item));
    }
    pref.push_back(Add(Mul(pref.back(), kBase), 2));
    pref_size.push_back(pref_size.back() + 1);
    ll curr_h = pref.back();
    node.Erase(h[u]);
    node.Insert(curr_h);
    if (node.res > best) {
        best = node.res;
        vert = u;
    }
    node.Erase(curr_h);
    for (int i = 0; i < items.size(); ++i) {
        const auto& item = items[i];
        int v = get<2>(item);
        if (v == p) { continue; }
        int len = pref_size.back() - pref_size[i + 2];
        ll new_uph = Add(Mul(pref[i + 1], pow_base[len]), Sub(pref.back(), Mul(pref[i + 2], pow_base[len])));
        ll new_szp = sz[0] - sz[v];
        node.Insert(new_uph);
        Dfs(v, u, new_uph, new_szp);
        node.Erase(new_uph);
    }
    node.Insert(h[u]);
}

void Precalc() {
    pow_base[0] = 1;
    for (int i = 1; i < kM; ++i) {
        pow_base[i] = Mul(pow_base[i - 1], kBase);
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    Precalc();
    int n; cin >> n;
    for (int i = 0; i + 1 < n; ++i) {
        int u, v; cin >> u >> v;
        g[u - 1].push_back(v - 1);
        g[v - 1].push_back(u - 1);
    }
    DfsHash(0);
    for (int u = 0; u < n; ++u) {
        node.Insert(h[u]);
    }
    Dfs(0);
    cout << vert + 1 << '\n';
    return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <iomanip>
#include <queue>
#include <utility>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pci;
typedef pair<bool, int> pbi;
typedef pair<ll, int> pli;

const int kN = 100 * 1000;
const int kM = 2 * kN + 1;
const ll kMod = 18014398241046527LL;
const ll kBase = 3;

vector<int> g[kN];
ll pow_base[2 * kN];
ll h[kN];
int sz[kN];
map<ll, int> cnt;

ll Add(ll a, ll b) {
    // assert(a >= 0 && b >= 0);
    ll res = a + b;
    return res < kMod ? res : res - kMod;
}

ll Sub(ll a, ll b) {
    // assert(a >= 0 && b >= 0);
    ll res = a - b;
    return res < 0 ? res + kMod : res;
}

ll Mul(ll a, ll b) {
    // assert(a >= 0 && b >= 0);
    ll res = 0;
    ll carry = a;
    while (b) {
        if (b & 1) {
            res = Add(res, carry);
        }
        carry = Add(carry, carry);
        b >>= 1;
    }
    return res;
}

ll GetHash(const vector<pli>& items) {
    ll hh = 1;
    for (const auto& item : items) {
        hh = Add(Mul(hh, pow_base[item.second]), item.first);
    }
    hh = Add(Mul(hh, kBase), 2);
    return hh;
}

void DfsHash(int u, int p = -1) {
    vector<pli> items;
    sz[u] = 1;
    for (int v : g[u]) {
        if (v == p) { continue; }
        DfsHash(v, u);
        sz[u] += sz[v];
        items.emplace_back(h[v], 2 * sz[v]);
    }
    sort(items.begin(), items.end());
    h[u] = GetHash(items);
}

struct Node {
    map<ll, int> cnt;
    int res;

    Node() : res(0) {}

    void Insert(ll h) {
        ll val = ++cnt[h];
        if (val == 1) { ++res; }
        if (val == 2) { --res; }
    }

    void Erase(ll h) {
        auto it = cnt.find(h);
        // assert(it != cnt.end());
        --(it->second);
        if (it->second == 1) { ++res; }
        if (it->second == 0) { --res; cnt.erase(it); }
    }
};

Node node;
int best = -1, vert = -1;

void Dfs(int u, int p = -1, ll uph = 0, ll szp = 0) {
    vector<tuple<ll, int, int>> items = {make_tuple(uph, 2 * szp, p)};
    for (int v : g[u]) {
        if (v == p) { continue; }
        items.emplace_back(h[v], 2 * sz[v], v);
    }
    sort(items.begin(), items.end());
    vector<ll> pref = {0, 1};
    vector<int> pref_size = {0, 1};
    for (const auto& item : items) {
        pref.push_back(Add(Mul(pref.back(), pow_base[get<1>(item)]), get<0>(item)));
        pref_size.push_back(pref_size.back() + get<1>(item));
    }
    pref.push_back(Add(Mul(pref.back(), kBase), 2));
    pref_size.push_back(pref_size.back() + 1);
    ll curr_h = pref.back();
    node.Erase(h[u]);
    node.Insert(curr_h);
    if (node.res > best) {
        best = node.res;
        vert = u;
    }
    node.Erase(curr_h);
    for (int i = 0; i < items.size(); ++i) {
        const auto& item = items[i];
        int v = get<2>(item);
        if (v == p) { continue; }
        int len = pref_size.back() - pref_size[i + 2];
        ll new_uph = Add(Mul(pref[i + 1], pow_base[len]), Sub(pref.back(), Mul(pref[i + 2], pow_base[len])));
        ll new_szp = sz[0] - sz[v];
        node.Insert(new_uph);
        Dfs(v, u, new_uph, new_szp);
        node.Erase(new_uph);
    }
    node.Insert(h[u]);
}

void Precalc() {
    pow_base[0] = 1;
    for (int i = 1; i < kM; ++i) {
        pow_base[i] = Mul(pow_base[i - 1], kBase);
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    // Precalc();
    int n; cin >> n;
    for (int i = 0; i + 1 < n; ++i) {
        int u, v; cin >> u >> v;
        g[u - 1].push_back(v - 1);
        g[v - 1].push_back(u - 1);
    }
    return 0;
    DfsHash(0);
    for (int u = 0; u < n; ++u) {
        node.Insert(h[u]);
    }
    Dfs(0);
    cout << vert + 1 << '\n';
    return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <iomanip>
#include <queue>
#include <utility>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pci;
typedef pair<bool, int> pbi;
typedef pair<ll, int> pli;

const int kN = 100 * 1000;
const int kM = 2 * kN + 1;
const ll kMod = 18014398241046527LL;
const ll kBase = 7;

vector<int> g[kN];
ll pow_base[kM];
ll h[kN];
int sz[kN];
map<ll, int> cnt;

ll Add(ll a, ll b) {
    assert(a >= 0 && b >= 0);
    ll res = a + b;
    return res < kMod ? res : res - kMod;
}

ll Sub(ll a, ll b) {
    assert(a >= 0 && b >= 0);
    ll res = a - b;
    return res < 0 ? res + kMod : res;
}

ll Mul(ll a, ll b) {
    assert(a >= 0 && b >= 0);
    ll res = 0;
    ll carry = a;
    while (b) {
        if (b & 1) {
            res = Add(res, carry);
        }
        carry = Add(carry, carry);
        b >>= 1;
    }
    return res;
}

ll GetHash(const vector<pli>& items) {
    ll hh = 1;
    for (const auto& item : items) {
        hh = Add(Mul(hh, pow_base[item.second]), item.first);
    }
    hh = Add(Mul(hh, kBase), 2);
    return hh;
}

void DfsHash(int u, int p = -1) {
    vector<pli> items;
    sz[u] = 1;
    for (int v : g[u]) {
        if (v == p) { continue; }
        DfsHash(v, u);
        sz[u] += sz[v];
        items.emplace_back(h[v], 2 * sz[v]);
    }
    sort(items.begin(), items.end());
    h[u] = GetHash(items);
}

struct Node {
    map<ll, int> cnt;
    int res;

    Node() : res(0) {}

    void Insert(ll h) {
        ll val = ++cnt[h];
        if (val == 1) { ++res; }
        if (val == 2) { --res; }
    }

    void Erase(ll h) {
        auto it = cnt.find(h);
        assert(it != cnt.end());
        --(it->second);
        if (it->second == 1) { ++res; }
        if (it->second == 0) { --res; cnt.erase(it); }
    }
};

Node node;
int best = -1, vert = -1;

void Dfs(int u, int p = -1, ll uph = 0, ll szp = 0) {
    vector<tuple<ll, int, int>> items = {make_tuple(uph, 2 * szp, p)};
    for (int v : g[u]) {
        if (v == p) { continue; }
        items.emplace_back(h[v], 2 * sz[v], v);
    }
    sort(items.begin(), items.end());
    vector<ll> pref = {0, 1};
    vector<int> pref_size = {0, 1};
    for (const auto& item : items) {
        pref.push_back(Add(Mul(pref.back(), pow_base[get<1>(item)]), get<0>(item)));
        pref_size.push_back(pref_size.back() + get<1>(item));
    }
    pref.push_back(Add(Mul(pref.back(), kBase), 2));
    pref_size.push_back(pref_size.back() + 1);
    ll curr_h = pref.back();
    node.Erase(h[u]);
    node.Insert(curr_h);
    if (node.res > best) {
        best = node.res;
        vert = u;
    }
    node.Erase(curr_h);
    for (int i = 0; i < items.size(); ++i) {
        const auto& item = items[i];
        int v = get<2>(item);
        if (v == p) { continue; }
        int len = pref_size.back() - pref_size[i + 2];
        ll new_uph = Add(Mul(pref[i + 1], pow_base[len]), Sub(pref.back(), Mul(pref[i + 2], pow_base[len])));
        ll new_szp = sz[0] - sz[v];
        node.Insert(new_uph);
        Dfs(v, u, new_uph, new_szp);
        node.Erase(new_uph);
    }
    node.Insert(h[u]);
}

void Precalc() {
    pow_base[0] = 1;
    for (int i = 1; i < kM; ++i) {
        pow_base[i] = Mul(pow_base[i - 1], kBase);
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    Precalc();
    int n; cin >> n;
    for (int i = 0; i + 1 < n; ++i) {
        int u, v; cin >> u >> v;
        g[u - 1].push_back(v - 1);
        g[v - 1].push_back(u - 1);
    }
    DfsHash(0);
    for (int u = 0; u < n; ++u) {
        node.Insert(h[u]);
    }
    Dfs(0);
    cout << vert + 1 << '\n';
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll has(ll a) {
	return a * a * 231237 + a * 1023119 + 3213117;
}
int n;
vi eg[maxn];
ll dp[maxn]; // a子树的哈希
ll fr[maxn];
int dfn[maxn], sz[maxn];
int dfcnt = 0;
const ll dd = 307;
void dfs1(int a, int fa) {
	dfn[a] = ++dfcnt;
	sz[a] = 1;
	for (auto v : eg[a]) {
		if (v == fa) continue;
		dfs1(v, a);
		sz[a] += sz[v];
		dp[a] += has(dp[v]);
	}
	dp[a] += dd;
}
void dfs2(int a, int fa) {
	if (fa) {
		fr[a] = dp[fa] - has(dp[a]);
		if (fa != 1) fr[a] += has(fr[fa]);
	}
	for (auto v : eg[a]) {
		if (v == fa) continue;
		dfs2(v, a);
	}
}
int d[maxn];
void act(int l, int r) {
	if (l > r) return ;
	d[l]++, d[r + 1]--;
}
void upd(vector<pi> cur) {
	sort(cur.begin(), cur.end());
	int mx = 0;
	for (int i = 0; i < cur.size(); i++) {
		if (cur[i].fi > cur[i].se) continue;
		act(max(mx + 1, cur[i].fi), cur[i].se),
		mx = max(mx, cur[i].se);
	}
}
vector<pair<ll, int> > chk;
int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		eg[u].pb(v), eg[v].pb(u);
	}
	dfs1(1, 0);
	dfs2(1, 0);
//	cout << fr[2] << endl;
	for (int i = 1; i <= n; i++)
		chk.pb(mp(dp[i], i));//, cout << i << ' ' << dp[i] << endl;
	for (int i = 2; i <= n; i++)
		chk.pb(mp(fr[i], -i));
	sort(chk.begin(), chk.end());
//	cout << "AF" << endl;
	for (int i = 0; i < chk.size(); ) {
	//	cout << i << ' ' << chk[i].fi << endl;
//	cout << "???" << i << endl;
		int j = i;
		while (j < chk.size() && chk[j].fi == chk[i].fi) j++;
		vector<pi> cur;
		for (int k = i; k < j; k++) {
			int id = chk[k].se;
		//	cout << id << ' ';
			if (id > 0)
				cur.pb(mp(1, dfn[id] - 1)),
				cur.pb(mp(dfn[id] + sz[id], n));
			else
				id = -id,
				cur.pb(mp(dfn[id], dfn[id] + sz[id] - 1));
		}
		upd(cur);
	//	cout << endl;
		i = j;
	}
	for (int i = 1; i <= n; i++)
		d[i] += d[i - 1];
	int ea = -1, epl = 0;
	for (int i = 1; i <= n; i++) {
		int na = d[dfn[i]];
		if (na > ea) ea = na, epl = i;
	}
//	cout << ea << endl;
	cout << epl << endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll has(ll a) {
	return a * a * 231237 + a * 1023119 + 3213117;
}
int n;
vi eg[maxn];
ll dp[maxn]; // a子树的哈希
ll fr[maxn];
int dfn[maxn], sz[maxn];
int dfcnt = 0;
const ll dd = 307;
void dfs1(int a, int fa) {
	dfn[a] = ++dfcnt;
	sz[a] = 1;
	for (auto v : eg[a]) {
		if (v == fa) continue;
		dfs1(v, a);
		sz[a] += sz[v];
		dp[a] += has(dp[v]);
	}
	dp[a] += dd;
}
void dfs2(int a, int fa) {
	if (fa) {
		fr[a] = dp[fa] - has(dp[a]);
		if (fa != 1) fr[a] += has(fr[fa]);
	}
	for (auto v : eg[a]) {
		if (v == fa) continue;
		dfs2(v, a);
	}
}
int d[maxn];
void act(int l, int r) {
	if (l > r) return ;
	d[l]++, d[r + 1]--;
}
void upd(vector<pi> cur) {
	sort(cur.begin(), cur.end());
	int mx = 0;
	for (int i = 0; i < cur.size(); i++) {
		if (cur[i].fi > cur[i].se) continue;
		act(max(mx + 1, cur[i].fi), cur[i].se),
		mx = max(mx, cur[i].se);
	}
}
vector<pair<ll, int> > chk;
int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		eg[u].pb(v), eg[v].pb(u);
	}
	dfs1(1, 0);
	dfs2(1, 0);
//	cout << fr[2] << endl;
	for (int i = 1; i <= n; i++)
		chk.pb(mp(dp[i], i));//, cout << i << ' ' << dp[i] << endl;
	for (int i = 2; i <= n; i++)
		chk.pb(mp(fr[i], -i));
	sort(chk.begin(), chk.end());
//	cout << "AF" << endl;
	for (int i = 0; i < chk.size(); ) {
	//	cout << i << ' ' << chk[i].fi << endl;
//	cout << "???" << i << endl;
		int j = i;
		while (j < chk.size() && chk[j].fi == chk[i].fi) j++;
		vector<pi> cur;
		for (int k = i; k < j; k++) {
			int id = chk[k].se;
		//	cout << id << ' ';
			if (id > 0)
				cur.pb(mp(1, dfn[id] - 1)),
				cur.pb(mp(dfn[id] + sz[id], n));
			else
				id = -id,
				cur.pb(mp(dfn[id], dfn[id] + sz[id] - 1));
		}
		upd(cur);
	//	cout << endl;
		i = j;
	}
	for (int i = 1; i <= n; i++)
		d[i] += d[i - 1];
	int ea = 0, epl = 0;
	for (int i = 1; i <= n; i++) {
		int na = d[dfn[i]];
		if (na > ea) ea = na, epl = i;
	}
//	cout << ea << endl;
	cout << epl << endl;
	return 0;
}


#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define forg(i,gu) for (int i=gu;~i;i=e[i].next)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
//const ll inf=0x3f3f3f3f3f3f3f3fll;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
const ll mo=ll(1e18)+3;
//int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}
ll mul(ll x,ll y){
	x%=mo,y%=mo;
	return (x*y-(ll)(x/(long double)mo*y)*mo+mo)%mo;
}
namespace myrand{
	// rand : [0,2^31)
	// randint : [-2^31,2^31)
	// randll : [-2^63,2^63)
	// randbit : 0,1
	unsigned int x[5]={107896582, 1107972621, 1195573091, 1224749359, 241825441};
	unsigned int get16(){
		unsigned long long tmp=(107374182ll*x[0]+104480ll*x[4]);
		unsigned int res=(tmp>>31)+(tmp&0x7fffffffu);
		x[0]=x[1],x[1]=x[2],x[2]=x[3],x[3]=x[4];
		return x[4]=res>=2147483647?res-2147483647:res;
	}
	void mysrand(unsigned int seed){
		for (int i=0;i<5;i++) seed=(seed+1)%2147483647,x[i]=seed;
		for (int i=0;i<5;i++) get16();
	}
	int randint(){
		int res=0;
		res+=int(get16());
		res+=int(get16())<<16;
		return res;
	}
	long long randll(){
		long long res=0;
		res+=(long long)(get16());
		res+=(long long)(get16())<<16;
		res+=(long long)(get16())<<32;
		res+=(long long)(get16())<<48;
		return res;
	}
	int randbit(){
		return ((get16())>>7)&1;
	}
	int myrand(){
		int x=randint();
		if(x<0)return ~x;
		return x;
	}
	template<typename RandomAccessIterator>void my_randomshuffle(RandomAccessIterator first,RandomAccessIterator last){
		int n=last-first;
		for (int i=1;i<n;i++){
			int to=myrand()%(i+1);
			swap(first[to],first[i]);
		}
	}
#define rand myrand::myrand
#define srand myrand::mysrand
#define random_shuffle myrand::my_randomshuffle
};

ll wei[111111];

// manually set n = number of vertices
// vertex index from 1 to n
// first call tree_init();
// ae(u,v) only one direction

const int TREE_MAXV=300000+5;
struct edge{int v,next;}e[TREE_MAXV*2];int g[TREE_MAXV],etot;
int qu[TREE_MAXV],pre[TREE_MAXV];
int h[333333];
ll has[333333];
int n;
void ae(int u,int v){
	e[etot].v=v;
	e[etot].next=g[u];g[u]=etot++;
}
void tree_init(){
	static bool ini=0;
	if(!ini){
		ini=1;
		memset(g,-1,sizeof(g));
	}else{
		for (int i=0;i<=n;i++)g[i]=-1;
	}
	etot=0;
}
void readedge(){
	for (int i=1;i<n;i++){
		int x,y;gn(x);gn(y);
		ae(x,y);ae(y,x);
	}
}

void dfs(int u,int pr){
	for(int i=g[u];~i;i=e[i].next)if(e[i].v!=pr){
		dfs(e[i].v,u);
		upmax(h[u],h[e[i].v]+1);
	}
	ll ret=1;
	for(int i=g[u];~i;i=e[i].next)if(e[i].v!=pr){
		ret=mul(ret,wei[h[u]]+has[e[i].v]);
	}
	has[u]=ret;
}
ll has2[333333];
ll hasful[333333];
int h2[333333];
ll lef1[333333],rig1[333333];
ll lef2[333333],rig2[333333];
void dfs2(int u,int pr){
	int mh=0,sh=0;
	for(int i=g[u];~i;i=e[i].next)if(e[i].v!=pr){
		int tmp=h[e[i].v]+1;
		if(tmp>=mh){
			sh=mh;
			mh=tmp;
		}else if(tmp>=sh){
			sh=tmp;
		}
	}
	if(pr!=0){
		int tmp=h2[u]+1;
		if(tmp>=mh){
			sh=mh;
			mh=tmp;
		}else if(tmp>=sh){
			sh=tmp;
		}
	}
	int deg=0;
	for(int i=g[u];~i;i=e[i].next)if(e[i].v!=pr){
		++deg;
		rig1[deg]=lef1[deg]=(has[e[i].v]+wei[mh])%mo;
		rig2[deg]=lef2[deg]=(has[e[i].v]+wei[sh])%mo;
	}
	if(pr==0)lef1[0]=lef2[0]=1;
	else lef1[0]=(has2[u]+wei[mh])%mo,lef2[0]=(has2[u]+wei[sh])%mo;
	rig1[deg+1]=rig2[deg+1]=1;

	rep(i,1,deg+1)lef1[i]=mul(lef1[i-1],lef1[i]),lef2[i]=mul(lef2[i-1],lef2[i]);
	per(i,1,deg+1)rig1[i]=mul(rig1[i+1],rig1[i]),rig2[i]=mul(rig2[i+1],rig2[i]);

	if(u==1)hasful[u]=has[u];
	else hasful[u]=lef1[deg];

	int curd=0;
	for(int i=g[u];~i;i=e[i].next)if(e[i].v!=pr){
		++curd;
		if(h[e[i].v]+1!=mh){
			has2[e[i].v]=mul(lef1[curd-1],rig1[curd+1]);
			h2[e[i].v]=mh;
		} else {
			has2[e[i].v]=mul(lef2[curd-1],rig2[curd+1]);
			h2[e[i].v]=sh;
		}
	}
	for(int i=g[u];~i;i=e[i].next)if(e[i].v!=pr){
		dfs2(e[i].v,u);
	}
}

map<ll,int> ma;
int cnt=0;

int an=0;int out;
void add(ll x){
	if((++ma[x])==1)cnt++;
}
void del(ll x){
	if((--ma[x])==0)cnt--;
}

void dfs3(int u,int pr){
	debug("when %d has %d\n",u,cnt);
	if(upmax(an,cnt))out=u;
	for (int i=g[u];~i;i=e[i].next)if(pr!=e[i].v){
		del(hasful[u]);
		del(has[e[i].v]);
		add(has2[e[i].v]);
		add(hasful[e[i].v]);
		dfs3(e[i].v,u);
		add(hasful[u]);
		add(has[e[i].v]);
		del(has2[e[i].v]);
		del(hasful[e[i].v]);
	}
}
int main()
{
#ifdef JCVB
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int _time_jc=clock();
#endif
	srand(2343);
	rep(i,0,101111){
		wei[i]=myrand::randll()%mo;
	}
	gn(n);
	tree_init();
	readedge();

	dfs(1,0);

	dfs2(1,0);

	rep(u,1,n+1)add(has[u]);

	dfs3(1,0);

	printf("%d\n",out);

#ifdef JCVB
	debug("time: %d\n",int(clock()-_time_jc));
#endif
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 100100;

LL key;
LL pw[(maxn << 1) + 5];

inline LL get_lucky()
{
	while (1)
	{
		LL x = 1;
		REP(i, 1, 64) if (rand() >> 10 & 1) x |= 1LL << i;
		LL val = x;
		bool failed = 0;
		REP(i, 0, 30)
		{
			val *= val;
			if (val == 1) { failed = 1; break; }
		}
		if (failed) continue;
		return x;
	}
	assert(0);
	return -1;
}

struct edge
{
	int id, nxt;

	edge() { }
	edge(int _id, int _nxt): id(_id), nxt(_nxt) { }

};

edge e[(maxn << 1) + 5];
int st[maxn + 5], en = 0;

inline void add_edge(int x, int y)
{
	e[en] = edge(y, st[x]), st[x] = en++;
}

int n;

int sz[maxn + 5];
int Max[maxn + 5];

void pre_dfs(int x, int f = -1)
{
	sz[x] = 1;
	Max[x] = 0;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		int y = e[i].id;
		if (y == f) continue;
		pre_dfs(y, x);
		sz[x] += sz[y];
		chkmax(Max[x], sz[y]);
	}
}

LL w[maxn + 5];

int id[maxn + 5];
int dep[maxn + 5];

void dfs0(int x, int f = -1)
{
	vector<pair<int, LL> > v;
	sz[x] = 1;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		int y = e[i].id;
		if (y == f) continue;
		dep[y] = dep[x] + 1;
		dfs0(y, x);
		v.pb(mp(sz[y], w[y]));
		sz[x] += sz[y];
	}
	sort(ALL(v));
	w[x] = 1;
	for (auto &u : v) (w[x] *= pw[u.x << 1]) += u.y;
	w[x] *= key;
}

int cnt[maxn + 5];

int tot = 0;

int ansp = -1, ans = -1;

void dfs1(int x, int f = -1)
{
	if (chkmax(ans, tot + dep[x] + 1)) ansp = x;
	if (!--cnt[id[x]]) --tot;
	for (int i = st[x]; i != -1; i = e[i].nxt)
	{
		int y = e[i].id;
		if (y == f) continue;
		dfs1(y, x);
	}
	if (!cnt[id[x]]++) ++tot;
}

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	key = get_lucky();
	pw[0] = 1;
	REP(i, 0, maxn) pw[i + 1] = pw[i] * key;
	memset(st, -1, sizeof st), en = 0;
	scanf("%d", &n);
	REP(i, 0, n - 1)
	{
		int x, y;
		scanf("%d%d", &x, &y), --x, --y;
		add_edge(x, y);
		add_edge(y, x);
	}
	pre_dfs(0);
	int rt = -1;
	REP(i, 0, n)
	{
		chkmax(Max[i], n - sz[i]);
		if (rt == -1 || Max[i] < Max[rt]) rt = i;
	}
	dep[rt] = 0;
	dfs0(rt);
	static LL ww[maxn + 5];
	memcpy(ww, w, sizeof ww);
	sort(ww, ww + n);
	REP(i, 0, n) id[i] = lower_bound(ww, ww + n, w[i]) - ww;
	memset(cnt, 0, sizeof cnt);
	REP(i, 0, n) if ((sz[i] << 1) <= n)
	{
		if (!cnt[id[i]]++) ++tot;
	}
	dfs1(rt);
	printf("%d\n", ansp + 1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
ll seed[maxn];
ll Rand() {
	return ((ll)rand()<<48)|((ll)rand()<<32)|((ll)rand()<<16)|rand();
}
vector<int> G[maxn];
ll h[maxn];
map<ll,int> mp,cnt;
int tot,sum,ans;
void dfs_init(int x,int par) {
	h[x]=seed[0];
	for(auto v:G[x]) {
		if(v==par) continue;
		dfs_init(v,x);
		h[x]+=seed[mp[h[v]]];
	}
	if(mp.count(h[x])==0) mp[h[x]]=++tot;
	cnt[h[x]]++;
}
int idx=1;
void dfs(int x,int par,ll H) {
	cnt[h[x]]--;
	if(cnt[h[x]]==0) --sum;
	if(x>1) h[x]+=seed[mp[H]];
	if(!mp.count(h[x])) mp[h[x]]=++tot;
	/*
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]+=seed[mp[H]];
		if(mp.count(h[x])==0) mp[h[x]]=++tot;
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	*/
	if(sum+1>ans) idx=x,ans=sum+1;
	for(auto v:G[x]) {
		if(v==par) continue;
		ll t=h[x]-seed[mp[h[v]]];
		cnt[t]++;
		if(cnt[t]==1) sum++;
		if(!mp.count(t)) mp[t]=+tot;

		dfs(v,x,t);

		cnt[t]--;
		if(cnt[t]==0) --sum;
	}
	if(x>1) h[x]-=seed[mp[H]];
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	/*
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]-=seed[mp[H]];
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	*/
}
int main() {
	srand(time(0));
	for(int i = 0; i < maxn; ++i) seed[i]=Rand();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs_init(1,1);
	ans=sum=tot;
	dfs(1,1,0);
	assert(tot<maxn);
	cout<<idx<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5;
ll seed[maxn];
ll Rand() {
	return ((ll)rand()<<48)|((ll)rand()<<32)|(rand()<<16)|rand();
}
vector<int> G[maxn];
ll h[maxn];
map<ll,int> mp,cnt;
int tot,sum,ans;
void dfs_init(int x,int par) {
	h[x]=seed[0];
	for(auto v:G[x]) {
		if(v==par) continue;
		dfs_init(v,x);
		h[x]+=seed[mp[h[v]]];
	}
	if(mp.count(h[x])==0) mp[h[x]]=++tot;
	cnt[h[x]]++;
}
int idx=1;
void dfs(int x,int par,ll H) {
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]+=seed[mp[H]];
		if(mp.count(h[x])==0) mp[h[x]]=++tot;
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	if(sum>ans) idx=x,ans=sum;
	cnt[h[x]]--;
	if(cnt[h[x]]==0) --sum;
	for(auto v:G[x]) {
		if(v==par) continue;
		ll t=h[x]-seed[mp[h[v]]];
		cnt[t]++;
		if(cnt[t]==1) sum++;
		if(!mp.count(t)) mp[t]=+tot;

		dfs(v,x,h[x]-seed[mp[h[v]]]);

		cnt[t]--;
		if(cnt[t]==0) --sum;
	}
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]-=seed[mp[H]];
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
}
int main() {
	srand(time(0));
	for(int i = 0; i < maxn; ++i) seed[i]=Rand();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs_init(1,1);
	ans=sum=tot;
	dfs(1,1,0);
	cout<<idx<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
ll seed[maxn];
ll Rand() {
	return ((ll)rand()<<48)|((ll)rand()<<32)|(rand()<<16)|rand();
}
vector<int> G[maxn];
ll h[maxn];
map<ll,int> mp,cnt;
int tot,sum,ans;
void dfs_init(int x,int par) {
	h[x]=seed[0];
	for(auto v:G[x]) {
		if(v==par) continue;
		dfs_init(v,x);
		h[x]+=seed[mp[h[v]]];
	}
	if(mp.count(h[x])==0) mp[h[x]]=++tot;
	cnt[h[x]]++;
}
int idx=1;
void dfs(int x,int par,ll H) {
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]+=seed[mp[H]];
		if(mp.count(h[x])==0) mp[h[x]]=++tot;
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	if(sum>ans) idx=x,ans=sum;
	cnt[h[x]]--;
	if(cnt[h[x]]==0) --sum;
	for(auto v:G[x]) {
		if(v==par) continue;
		ll t=h[x]-seed[mp[h[v]]];
		cnt[t]++;
		if(cnt[t]==1) sum++;
		if(!mp.count(t)) mp[t]=+tot;

		dfs(v,x,h[x]-seed[mp[h[v]]]);

		cnt[t]--;
		if(cnt[t]==0) --sum;
	}
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]-=seed[mp[H]];
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
}
int main() {
	srand(time(0));
	for(int i = 0; i < maxn; ++i) seed[i]=Rand();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs_init(1,1);
	ans=sum=tot;
	dfs(1,1,0);
	cout<<idx<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
ll seed[maxn];
ll Rand() {
	return ((ll)rand()<<48)|((ll)rand()<<32)|((ll)rand()<<16)|rand();
}
vector<int> G[maxn];
ll h[maxn];
map<ll,int> mp,cnt;
int tot,sum,ans;
void dfs_init(int x,int par) {
	h[x]=seed[0];
	for(auto v:G[x]) {
		if(v==par) continue;
		dfs_init(v,x);
		h[x]+=seed[mp[h[v]]];
	}
	if(mp.count(h[x])==0) mp[h[x]]=++tot;
	cnt[h[x]]++;
}
int idx=1;
void dfs(int x,int par,ll H) {
	cnt[h[x]]--;
	if(cnt[h[x]]==0) --sum;
	ll w=h[x];
	if(x>1) w+=seed[mp[H]];
	// if(x>1) h[x]+=seed[mp[H]];
	//if(!mp.count(h[x])) mp[h[x]]=++tot;
	/*
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]+=seed[mp[H]];
		if(mp.count(h[x])==0) mp[h[x]]=++tot;
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	*/
	if(sum+1>ans) idx=x,ans=sum+1;
	for(auto v:G[x]) {
		if(v==par) continue;
		ll t=w-seed[mp[h[v]]];
		if(!mp.count(t)) mp[t]=+tot;
		cnt[t]++;
		if(cnt[t]==1) ++sum;

		dfs(v,x,t);

		cnt[t]--;
		if(cnt[t]==0) --sum;
	}
	// if(x>1) h[x]-=seed[mp[H]];
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	/*
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]-=seed[mp[H]];
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	*/
}
int main() {
	srand(time(0));
	for(int i = 0; i < maxn; ++i) seed[i]=Rand();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs_init(1,1);
	ans=sum=tot;
	dfs(1,1,0);
	assert(tot<maxn);
	cout<<idx<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
ll seed[maxn];
ll Rand() {
	return ((ll)rand()<<48)|((ll)rand()<<32)|((ll)rand()<<16)|rand();
}
vector<int> G[maxn];
ll h[maxn];
map<ll,int> mp,cnt;
int tot,sum,ans;
void dfs_init(int x,int par) {
	h[x]=seed[0];
	for(auto v:G[x]) {
		if(v==par) continue;
		dfs_init(v,x);
		h[x]+=seed[mp[h[v]]];
	}
	if(mp.count(h[x])==0) mp[h[x]]=++tot;
	cnt[h[x]]++;
}
int idx=1;
void dfs(int x,int par,ll H) {
	cnt[h[x]]--;
	if(cnt[h[x]]==0) --sum;
	ll w=h[x];
	if(x>1) w+=seed[mp[H]];
	// if(x>1) h[x]+=seed[mp[H]];
	//if(!mp.count(h[x])) mp[h[x]]=++tot;
	/*
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]+=seed[mp[H]];
		if(mp.count(h[x])==0) mp[h[x]]=++tot;
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	*/
	if(sum+1>ans) idx=x,ans=sum+1;
	for(auto v:G[x]) {
		if(v==par) continue;
		ll t=w-seed[mp[h[v]]];
		if(!mp.count(t)) mp[t]=+tot;
		cnt[t]++;
		if(cnt[t]==1) ++sum;

		dfs(v,x,t);

		cnt[t]--;
		if(cnt[t]==0) --sum;
	}
	// if(x>1) h[x]-=seed[mp[H]];
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	/*
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]-=seed[mp[H]];
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	*/
}
int main() {
    int fdasfaere=234243;
	srand(time(0));
	for(int i = 0; i < maxn; ++i) seed[i]=Rand();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs_init(1,1);
	ans=sum=tot;
	dfs(1,1,0);
	assert(tot<maxn);
	cout<<idx<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
ll seed[maxn];
ll Rand() {
	return ((ll)rand()<<48)|((ll)rand()<<32)|((ll)rand()<<16)|rand();
}
vector<int> G[maxn];
ll h[maxn];
map<ll,int> mp,cnt;
int tot,sum,ans;
void dfs_init(int x,int par) {
	h[x]=seed[0];
	for(auto v:G[x]) {
		if(v==par) continue;
		dfs_init(v,x);
		h[x]+=seed[mp[h[v]]];
	}
	if(mp.count(h[x])==0) mp[h[x]]=++tot;
	cnt[h[x]]++;
}
int idx=1;
void dfs(int x,int par,ll H) {
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]+=seed[mp[H]];
		if(mp.count(h[x])==0) mp[h[x]]=++tot;
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	if(sum>ans) idx=x,ans=sum;
	cnt[h[x]]--;
	if(cnt[h[x]]==0) --sum;
	for(auto v:G[x]) {
		if(v==par) continue;
		ll t=h[x]-seed[mp[h[v]]];
		cnt[t]++;
		if(cnt[t]==1) sum++;
		if(!mp.count(t)) mp[t]=+tot;

		dfs(v,x,t);

		cnt[t]--;
		if(cnt[t]==0) --sum;
	}
	if(x>1) h[x]-=seed[mp[H]];
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	/*
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]-=seed[mp[H]];
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	*/
}
int main() {
	srand(time(0));
	for(int i = 0; i < maxn; ++i) seed[i]=Rand();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs_init(1,1);
	ans=sum=tot;
	dfs(1,1,0);
	cout<<idx<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
ll seed[maxn];
ll Rand() {
	return ((ll)rand()<<48)|((ll)rand()<<32)|(rand()<<16)|rand();
}
vector<int> G[maxn];
ll h[maxn];
map<ll,int> mp,cnt;
int tot,sum,ans;
void dfs_init(int x,int par) {
	h[x]=seed[0];
	for(auto v:G[x]) {
		if(v==par) continue;
		dfs_init(v,x);
		h[x]+=seed[mp[h[v]]];
	}
	if(mp.count(h[x])==0) mp[h[x]]=++tot;
	cnt[h[x]]++;
}
int idx=1;
void dfs(int x,int par,ll H) {
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]+=seed[mp[H]];
		if(mp.count(h[x])==0) mp[h[x]]=++tot;
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	if(sum>ans) idx=x,ans=sum;
	cnt[h[x]]--;
	if(cnt[h[x]]==0) --sum;
	for(auto v:G[x]) {
		if(v==par) continue;
		ll t=h[x]-seed[mp[h[v]]];
		cnt[t]++;
		if(cnt[t]==1) sum++;
		if(!mp.count(t)) mp[t]=++tot;

		dfs(v,x,h[x]-seed[mp[h[v]]]);

		cnt[t]--;
		if(cnt[t]==0) --sum;
	}
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]-=seed[mp[H]];
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
}
int main() {
	srand(time(0));
	for(int i = 0; i < maxn; ++i) seed[i]=Rand();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs_init(1,1);
	ans=sum=tot;
	dfs(1,1,0);
	cout<<idx<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
ll seed[maxn];
ll Rand() {
	return ((ll)rand()<<48)|((ll)rand()<<32)|((ll)rand()<<16)|rand();
}
vector<int> G[maxn];
ll h[maxn];
map<ll,int> mp,cnt;
int tot,sum,ans;
void dfs_init(int x,int par) {
	h[x]=seed[0];
	for(auto v:G[x]) {
		if(v==par) continue;
		dfs_init(v,x);
		h[x]+=seed[mp[h[v]]];
	}
	if(mp.count(h[x])==0) mp[h[x]]=++tot;
	cnt[h[x]]++;
}
int idx=1;
void dfs(int x,int par,ll H) {
	cnt[h[x]]--;
	if(cnt[h[x]]==0) --sum;
	ll w=h[x];
	if(x>1) w+=seed[mp[H]];
	// if(x>1) h[x]+=seed[mp[H]];
	//if(!mp.count(h[x])) mp[h[x]]=++tot;
	/*
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]+=seed[mp[H]];
		if(mp.count(h[x])==0) mp[h[x]]=++tot;
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	*/
	if(sum+1>ans) idx=x,ans=sum+1;
	for(auto v:G[x]) {
		if(v==par) continue;
		ll t=w-seed[mp[h[v]]];
		if(!mp.count(t)) mp[t]=++tot;
		cnt[t]++;
		if(cnt[t]==1) ++sum;

		dfs(v,x,t);

		cnt[t]--;
		if(cnt[t]==0) --sum;
	}
	// if(x>1) h[x]-=seed[mp[H]];
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	/*
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]-=seed[mp[H]];
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	*/
}
int main() {
	srand(time(0));
	for(int i = 0; i < maxn; ++i) seed[i]=Rand();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs_init(1,1);
	ans=sum=tot;
	dfs(1,1,0);
	assert(tot<maxn);
	cout<<idx<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
ll seed[maxn];
ll Rand() {
	return ((ll)rand()<<48)|((ll)rand()<<32)|(rand()<<16)|rand();
}
vector<int> G[maxn];
ll h[maxn];
map<ll,int> mp,cnt;
int tot,sum,ans;
void dfs_init(int x,int par) {
	h[x]=0;
	for(auto v:G[x]) {
		if(v==par) continue;
		dfs_init(v,x);
		h[x]+=seed[mp[h[v]]];
	}
	if(mp.count(h[x])==0) mp[h[x]]=++tot;
	cnt[h[x]]++;
}
int idx=1;
void dfs(int x,int par,ll H) {
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]+=seed[mp[H]];
		if(mp.count(h[x])==0) mp[h[x]]=++tot;
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
	if(sum>ans) idx=x,ans=sum;
	cnt[h[x]]--;
	if(cnt[h[x]]==0) --sum;
	for(auto v:G[x]) {
		if(v==par) continue;
		ll t=h[x]-seed[mp[h[v]]];
		cnt[t]++;
		if(cnt[t]==1) sum++;
		if(!mp.count(t)) mp[t]=++tot;

		dfs(v,x,h[x]-seed[mp[h[v]]]);

		cnt[t]--;
		if(cnt[t]==0) --sum;
	}
	cnt[h[x]]++;
	if(cnt[h[x]]==1) ++sum;
	if(x>1) {
		cnt[h[x]]--;
		if(cnt[h[x]]==0) --sum;
		h[x]-=seed[mp[H]];
		cnt[h[x]]++;
		if(cnt[h[x]]==1) ++sum;
	}
}
int main() {
	srand(time(0));
	for(int i = 0; i < maxn; ++i) seed[i]=Rand();
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n-1; ++i) {
		int x,y;
		scanf("%d%d", &x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs_init(1,1);
	ans=sum=tot;
	dfs(1,1,0);
	cout<<idx<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007ll
const int N=1e5+4;
typedef long long ll;
long long int h[N],s[N],pr[N];
map<long long,int>cnt;
long long c,cmax=-1,ans;
const long long prm=1e9+7;
vector<int>g[N];
ll exp (ll b, ll e) {
	if (b == 1 || e == 0) return 1;
	if(e == 1) return b%MOD;
	if(e == 2) return (b*b)%MOD;
	return ( (e%2 == 0)? exp(exp(b,e/2),2)%MOD : (b * (exp(exp(b,e/2),2)%MOD))%MOD );
}
void dfs(int v,int p)
{
    s[v]=1;
    pr[v]=1;
    for(int i=0;i<g[v].size();i++)
    {
        if(g[v][i]==p) continue;
        dfs(g[v][i],v);
        s[v]=(s[v]^h[g[v][i]])%MOD;
        pr[v]=(pr[v]*h[g[v][i]])%MOD;

    }
    ++cnt[h[v]=(prm^(s[v]*pr[v])%MOD)%MOD];
}
void dfs1(int v,int p)
{
    long long t1=h[p],t2=h[v];
    if(v!=p)
    {
        long long ns,np,u;
        np=(pr[p]*exp(h[v],MOD-2)%MOD);
        ns=(h[v]^s[p])%MOD;
        ++cnt[h[p]=(prm^(np*ns)%MOD)%MOD];
        u=--cnt[t2];
        if(u==0)
            cnt.erase(t1);
        s[v] =(s[v]^h[p])%MOD;
        pr[v]=(s[v]*h[p])%MOD;
        u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = (prm ^ (s[v] * pr[v])%MOD) % MOD];

    }
    ll sz = cnt.size();
	if (sz > cmax) { cmax = sz; ans = v; }
	for (int i = 0 ; i < g[v].size() ; ++i) {
		if (g[v][i] == p) continue;
		dfs1 (g[v][i], v);
	}
	if (v != p) {
		ll u = (--cnt[h[p]]);
		if (u == 0) cnt.erase(h[p]);
		++cnt[h[p] = t1];
		u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = t2];
	}

}
int main()
{
    int n;
    scanf("%d",&n);
    int i,u,v;
    for(i=1;i<n;i++)
    {
        scanf("%d %d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);

    }
    dfs(1,1);
    dfs1(1,1);
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007ll
const int N=1e5+4;
typedef long long ll;
long long int h[N],s[N],pr[N];
map<long long,int>cnt;
long long c,cmax=-1,ans;
const long long prm=780291637;
vector<int>g[N];
ll exp (ll b, ll e) {
	if (b == 1 || e == 0) return 1;
	if(e == 1) return b%MOD;
	if(e == 2) return (b*b)%MOD;
	return ( (e%2 == 0)? exp(exp(b,e/2),2)%MOD : (b * (exp(exp(b,e/2),2)%MOD))%MOD );
}
void dfs(int v,int p)
{
    s[v]=1;
    pr[v]=1;
    for(int i=0;i<g[v].size();i++)
    {
        if(g[v][i]==p) continue;
        dfs(g[v][i],v);
        s[v]=(s[v]^h[g[v][i]])%MOD;
        pr[v]=(pr[v]*h[g[v][i]])%MOD;

    }
    ++cnt[h[v]=(prm^(s[v]*pr[v])%MOD)%MOD];
}
void dfs1(int v,int p)
{
    long long t1=h[p],t2=h[v];
    if(v!=p)
    {
        long long ns,np,u;
        np=(pr[p]*exp(h[v],MOD-2)%MOD);
        ns=(h[v]^s[p])%MOD;
        ++cnt[h[p]=(prm^(np*ns)%MOD)%MOD];
        u=--cnt[t2];
        if(u==0)
            cnt.erase(t1);
        s[v] =(s[v]^h[p])%MOD;
        pr[v]=(s[v]*h[p])%MOD;
        u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = (prm ^ (s[v] * pr[v])%MOD) % MOD];

    }
    ll sz = cnt.size();
	if (sz > cmax) { cmax = sz; ans = v; }
	for (int i = 0 ; i < g[v].size() ; ++i) {
		if (g[v][i] == p) continue;
		dfs1 (g[v][i], v);
	}
	if (v != p) {
		ll u = (--cnt[h[p]]);
		if (u == 0) cnt.erase(h[p]);
		++cnt[h[p] = t1];
		u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = t2];
	}

}
int main()
{
    int n;
    scanf("%d",&n);
    int i,u,v;
    for(i=1;i<n;i++)
    {
        scanf("%d %d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);

    }
    dfs(1,1);
    dfs1(1,1);
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007ll
const int N=1e5+4;
typedef long long ll;
long long int h[N],s[N],pr[N];
map<long long,int>cnt;
long long c,cmax=-1,ans;
const long long prm=1e9+7;
vector<int>g[N];
ll exp (ll b, ll e) {
	if (b == 1 || e == 0) return 1;
	if(e == 1) return b%MOD;
	if(e == 2) return (b*b)%MOD;
	return ( (e%2 == 0)? exp(exp(b,e/2),2)%MOD : (b * (exp(exp(b,e/2),2)%MOD))%MOD );
}
void dfs(int v,int p)
{
    s[v]=1;
    pr[v]=1;
    for(int i=0;i<g[v].size();i++)
    {
        if(g[v][i]==p) continue;
        dfs(g[v][i],v);
        s[v]=(s[v]^h[g[v][i]])%MOD;
        pr[v]=(pr[v]*h[g[v][i]])%MOD;

    }
    ++cnt[h[v]=(prm^(s[v]*pr[v])%MOD)%MOD];
}
void dfs1(int v,int p)
{
    long long t1=h[p],t2=h[v];
    if(v!=p)
    {
        long long ns,np,u;
        np=(pr[p]*exp(h[v],MOD-2)%MOD);
        ns=(h[v]^s[p])%MOD;
        ++cnt[h[p]=(prm^(np*ns)%MOD)%MOD];
        u=--cnt[t2];
        if(u==0)
            cnt.erase(t1);
        s[v] =(s[v]^h[p])%MOD;
        pr[v]=(s[v]*h[v])%MOD;
        u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = (prm ^ (s[v] * pr[v])%MOD) % MOD];

    }
    ll sz = cnt.size();
	if (sz > cmax) { cmax = sz; ans = v; }
	for (int i = 0 ; i < g[v].size() ; ++i) {
		if (g[v][i] == p) continue;
		dfs1 (g[v][i], v);
	}
	if (v != p) {
		ll u = (--cnt[h[p]]);
		if (u == 0) cnt.erase(h[p]);
		++cnt[h[p] = t1];
		u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = t2];
	}

}
int main()
{
    int n;
    scanf("%d",&n);
    int i,u,v;
    for(i=1;i<n;i++)
    {
        scanf("%d %d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);

    }
    dfs(1,1);
    dfs1(1,1);
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007ll
const int N=1e5+4;
typedef long long ll;
long long int h[N],s[N],pr[N];
map<long long,int>cnt;
long long c,cmax=-1,ans;
const long long prm=780291637;
vector<int>g[N];
ll exp (ll b, ll e) {
	if (b == 1 || e == 0) return 1;
	if(e == 1) return b%MOD;
	if(e == 2) return (b*b)%MOD;
	return ( (e%2 == 0)? exp(exp(b,e/2),2)%MOD : (b * (exp(exp(b,e/2),2)%MOD))%MOD );
}
void dfs(int v,int p)
{
    s[v]=1;
    pr[v]=1;
    for(int i=0;i<g[v].size();i++)
    {
        if(g[v][i]==p) continue;
        dfs(g[v][i],v);
        s[v]=(s[v]^h[g[v][i]])%MOD;
        pr[v]=(pr[v]*h[g[v][i]])%MOD;

    }
    ++cnt[h[v]=(prm^(s[v]*pr[v])%MOD)%MOD];
}
void dfs1(int v,int p)
{
    long long t1=h[p],t2=h[v];
    if(v!=p)
    {
        long long ns,np,u;
        np=(pr[p]*exp(h[v],MOD-2)%MOD);
        ns=(h[v]^s[p])%MOD;
        ++cnt[h[p]=(prm^(np*ns)%MOD)%MOD];
        u=(--cnt[t2]);
        if(u==0)
            cnt.erase(t1);
        s[v] =(s[v]^h[p])%MOD;
        pr[v]=(s[v]*h[p])%MOD;
        u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = (prm ^ (s[v] * pr[v])%MOD) % MOD];

    }
    ll sz = cnt.size();
	if (sz > cmax) { cmax = sz; ans = v; }
	for (int i = 0 ; i < g[v].size() ; ++i) {
		if (g[v][i] == p) continue;
		dfs1 (g[v][i], v);
	}
	if (v != p) {
		ll u = (--cnt[h[p]]);
		if (u == 0) cnt.erase(h[p]);
		++cnt[h[p] = t1];
		u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = t2];
	}

}
int main()
{
    int n;
    scanf("%d",&n);
    int i,u,v;
    for(i=1;i<n;i++)
    {
        scanf("%d %d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);

    }
    dfs(1,1);
    dfs1(1,1);
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007ll
const int N=1e5+4;
typedef long long ll;
long long int h[N],s[N],pr[N];
map<long long,int>cnt;
long long c,cmax=-1,ans;
const long long prm=780291637;
vector<int>g[N];
ll exp (ll b, ll e) {
	if (b == 1 || e == 0) return 1;
	if(e == 1) return b%MOD;
	if(e == 2) return (b*b)%MOD;
	return ( (e%2 == 0)? exp(exp(b,e/2),2)%MOD : (b * (exp(exp(b,e/2),2)%MOD))%MOD );
}
void dfs(int v,int p)
{
    s[v]=1;
    pr[v]=1;
    for(int i=0;i<g[v].size();i++)
    {
        if(g[v][i]==p) continue;
        dfs(g[v][i],v);
        s[v]=(s[v]^h[g[v][i]])%MOD;
        pr[v]=(pr[v]*h[g[v][i]])%MOD;

    }
    ++cnt[h[v]=(prm^(s[v]*pr[v])%MOD)%MOD];
}
void dfs1(int v,int p)
{
    long long t1=h[p],t2=h[v];
    if(v!=p)
    {
        long long ns,np,u;
        np=(pr[p]*exp(h[v],MOD-2)%MOD);
        ns=(h[v]^s[p])%MOD;
        ++cnt[h[p]=(prm^(np*ns)%MOD)%MOD];
        u=--cnt[t2];
        if(u==0)
            cnt.erase(t1);
        s[v] =(s[v]^h[p])%MOD;
        pr[v]=(s[v]*h[v])%MOD;
        u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = (prm ^ (s[v] * pr[v])%MOD) % MOD];

    }
    ll sz = cnt.size();
	if (sz > cmax) { cmax = sz; ans = v; }
	for (int i = 0 ; i < g[v].size() ; ++i) {
		if (g[v][i] == p) continue;
		dfs1 (g[v][i], v);
	}
	if (v != p) {
		ll u = (--cnt[h[p]]);
		if (u == 0) cnt.erase(h[p]);
		++cnt[h[p] = t1];
		u = (--cnt[h[v]]);
		if (u == 0) cnt.erase(h[v]);
		++cnt[h[v] = t2];
	}

}
int main()
{
    int n;
    scanf("%d",&n);
    int i,u,v;
    for(i=1;i<n;i++)
    {
        scanf("%d %d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);

    }
    dfs(1,1);
    dfs1(1,1);
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

constexpr unsigned P1 = 1000003, P2 = 1000033;
constexpr unsigned M1 = 1000000007, M2 = 1000000009;

int n;
vector<int> graph[100005];
unsigned long long hashes[100005];
map<unsigned long long, int> hcnt;
int cnt[100005];
int cent;

void cdfs(int t, int p)
{
	cnt[t] = 1;
	for (int nxt : graph[t])
	{
		if (nxt == p) continue;
		cdfs(nxt, t);
		cnt[t] += cnt[nxt];
	}

	for (int nxt : graph[t])
	{
		if (cnt[nxt] >= (n + 1) / 2) return;
	}

	if (cnt[t] >= (n + 1) / 2) cent = t;
}

void dfs1(int t, int p)
{
	unsigned h1 = 1, h2 = 1;

	vector<unsigned> child1, child2;

	for (int nxt : graph[t])
	{
		if (nxt == p) continue;
		dfs1(nxt, t);
		child1.push_back(hashes[nxt] >> 32);
		child2.push_back(hashes[nxt]);
	}

	sort(child1.begin(), child1.end());
	sort(child2.begin(), child2.end());

	for (int i = 0; i < child1.size(); i++)
	{
		h1 = (h1 * 1ull * P1 + child1[i] * (i + 1ull)) % M1;
		h2 = (h2 * 1ull * P2 + child2[i] * 1ull * (child1.size() - i)) % M2;
	}

	hashes[t] = (unsigned long long)h1 << 32 | h2;
	hcnt[hashes[t]]++;
}

int ans1, ans2;

void dfs2(int t, int p, int d)
{
	if (ans2 < d)
	{
		ans2 = d;
		ans1 = t;
	}

	for (int nxt : graph[t])
	{
		if (nxt == p) continue;
		if (hcnt[hashes[nxt]] >= 2) dfs2(nxt, t, d + 1);
		else dfs2(nxt, t, d);
	}
}

int main()
{
	scanf("%d", &n);
	if (n == 1)
	{
		printf("1\n");
		return 0;
	}

	for (int i = 1; i < n; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	cdfs(1, -1);
	dfs1(cent, -1);
	dfs2(cent, -1, 1);

	printf("%d\n", ans1);
}


#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
const int Mo=1e9+7;
const int Maxn=1e5+5;
inline int R()
{
    char c;int res,sign=1;
    while((c=getchar())>'9'||c<'0') if(c=='-') sign=-1;res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    return res*sign;
}
int n,m,First[Maxn],to[Maxn*2],Next[Maxn*2],cnt=1,dp[Maxn*2],size[Maxn*2],now,ans1,ans2;
inline void add(int z,int y)
{
    Next[++cnt]=First[z];
    First[z]=cnt;
    to[cnt]=y;
}
unordered_map<int,int>mp;
void insert(int x){if(mp[x]++==0) ++now;}
void Delete(int x){if(--mp[x]==0) --now;}
int dfs(int pos,int father,int fr)
{
    size[fr]=1;
    for(int k=First[pos];k;k=Next[k])
    {
        if(to[k]==father) continue;
        dp[fr]=(dp[fr]+dfs(to[k],pos,k))%Mo;
        size[fr]+=size[k];
    }
    dp[fr]=((dp[fr])*size[fr]+size[fr]*size[fr])%Mo;
    insert(dp[fr]);
    return dp[fr];
}
int deal(int pos,int father,int fr)
{
    if(fr && dp[fr] ) return dp[fr];
    dp[fr]=0;size[fr]=1;
    for(int k=First[pos];k;k=Next[k])
    {
        if(to[k]==father )continue;
        deal(to[k],pos,k);
        dp[fr]=(dp[fr]+dp[k])%Mo;
        size[fr]+=size[k];
    }
    dp[fr]=((dp[fr])*size[fr]+size[fr]*size[fr])%Mo;
    return dp[fr];
}
void dp1(int pos,int father,int fr)
{
    for(int k=First[pos];k;k=Next[k])
    {
        if(to[k]==father) continue;
        Delete(dp[k]);
        insert(dp[k^1]);
        if(now>ans1)
        {
            ans1=now;
            ans2=to[k];
        }
        dp1(to[k],pos,k);
        Delete(dp[k^1]);
        insert(dp[k]);
    }
}
signed main()
{
    n=R();
    int x,y;
    for(int i=1;i<n;i++)
    {
        x=R();y=R();
        add(x,y);
        add(y,x);
    }
    dfs(1,0,0);
    ans1=now;ans2=1;
    for(int i=2;i<=n;i++)deal(i,0,0);
    dp1(1,0,0);
	cout<<ans2;
}


#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
const int Mo=1e9+7;
const int Maxn=1e5+5;
inline int R()
{
    char c;int res,sign=1;
    while((c=getchar())>'9'||c<'0') if(c=='-') sign=-1;res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    return res*sign;
}
int n,m,First[Maxn],to[Maxn*2],Next[Maxn*2],cnt=1,dp[Maxn*2],size[Maxn*2],now,ans1,ans2;
inline void add(int z,int y)
{
    Next[++cnt]=First[z];
    First[z]=cnt;
    to[cnt]=y;
}
unordered_map<int,int>mp;
void insert(int x){if(mp[x]++==0) ++now;}
void Delete(int x){if(--mp[x]==0) --now;}
int dfs(int pos,int father,int fr)
{
    size[fr]=1;
    for(int k=First[pos];k;k=Next[k])
    {
        if(to[k]==father) continue;
        dp[fr]=(dp[fr]+dfs(to[k],pos,k))%Mo;
        size[fr]+=size[k];
    }
    dp[fr]=((dp[fr])*size[fr]+size[fr]*size[fr])%Mo;
    insert(dp[fr]);
    return dp[fr];
}

void deal(int pos,int father)
{
	int Sum=0;
	for(int k=First[pos];k;k=Next[k])Sum=(Sum+dp[k])%Mo;
	for(int k=First[pos];k;k=Next[k])
	{
		size[k^1]=n-size[k];
		dp[k^1]=(n-size[k])*(Sum-dp[k]+Mo)%Mo+(n-size[k])*(n-size[k]);
		dp[k^1]%=Mo;
		if(to[k]==father) continue;
    	deal(to[k],pos);
	}
}
void dp1(int pos,int father,int fr)
{
    for(int k=First[pos];k;k=Next[k])
    {
        if(to[k]==father) continue;
        Delete(dp[k]);
        insert(dp[k^1]);
        if(now>ans1){ans1=now;ans2=to[k];}
        dp1(to[k],pos,k);
        Delete(dp[k^1]);
        insert(dp[k]);
    }
}
signed main()
{
	//freopen("txt.in","r",stdin);
    n=R();
    int x,y;
    for(int i=1;i<n;i++)
    {
        x=R();y=R();
        add(x,y);
        add(y,x);
    }
    dfs(1,0,0);
    ans1=now;ans2=1;
	deal(1,0);
    dp1(1,0,0);
	cout<<ans2;
}


#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
const int Mo=1e9+7;
const int Maxn=1e5+5;
inline int R()
{
    char c;int res,sign=1;
    while((c=getchar())>'9'||c<'0') if(c=='-') sign=-1;res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    return res*sign;
}
int n,m,First[Maxn],to[Maxn*2],Next[Maxn*2],cnt=1,dp[Maxn*2],size[Maxn*2],now,ans1,ans2;
inline void add(int z,int y)
{
    Next[++cnt]=First[z];
    First[z]=cnt;
    to[cnt]=y;
}
unordered_map<int,int>mp;
void insert(int x){if(mp[x]++==0) ++now;}
void Delete(int x){if(--mp[x]==0) --now;}
int dfs(int pos,int father,int fr)
{
    size[fr]=1;
    for(int k=First[pos];k;k=Next[k])
    {
        if(to[k]==father) continue;
        dp[fr]=(dp[fr]+dfs(to[k],pos,k))%Mo;
        size[fr]+=size[k];
    }
    dp[fr]=((dp[fr])*size[fr]+size[fr]*size[fr])%Mo;
    insert(dp[fr]);
    return dp[fr];
}

void deal(int pos,int father)
{
	int Sum=0;
	for(int k=First[pos];k;k=Next[k])Sum=(Sum+dp[k])%Mo;
	for(int k=First[pos];k;k=Next[k])
	{
		size[k^1]=n-size[k];
		dp[k^1]=(n-size[k])*(Sum-dp[k]+Mo)%Mo;
		if(to[k]==father) continue;
    	deal(to[k],pos);
	}
}
void dp1(int pos,int father,int fr)
{
    for(int k=First[pos];k;k=Next[k])
    {
        if(to[k]==father) continue;
        Delete(dp[k]);
        insert(dp[k^1]);
        if(now>ans1){ans1=now;ans2=to[k];}
        dp1(to[k],pos,k);
        Delete(dp[k^1]);
        insert(dp[k]);
    }
}
signed main()
{
	//freopen("txt.in","r",stdin);
    n=R();
    int x,y;
    for(int i=1;i<n;i++)
    {
        x=R();y=R();
        add(x,y);
        add(y,x);
    }
    dfs(1,0,0);
    ans1=now;ans2=1;
	deal(1,0);
    dp1(1,0,0);
	cout<<ans2;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

vector<int> gph[100005];
int n;

lint dp[100005], dpb[100005], pdp[100005];
int h1, h2, h3, par[100005], in[100005], out[100005], piv;
bool vis[100005];

vector<int> dfn;
lint dfs(int x, int p){
	if(!vis[x]){
		dfn.push_back(x);
		vis[x] = 1;
		par[x] = p;
	}
	vector<lint> v;
	for(auto &i : gph[x]){
		if(i == p) continue;
		v.push_back((h1 * dfs(i, x)) ^ h2);
	}
	if(v.size() == 0) return dp[x] = 1;
	sort(v.begin(), v.end());
	lint ret = 0, coeff = 1;
	for(auto &i : v){
		ret += coeff * i;
		coeff *= h3;
	}
	dp[x] = ret;
	return ret;
}

vector<lint> lis[100005];
vector<lint> pref[100005], suff[100005], suff2[100005];
lint pw[100005];

void solve(){
	pw[0] = 1;
	for(int i=1; i<=n+3; i++) pw[i] = pw[i-1] * h3;
	for(int i=1; i<=n; i++){
		for(auto &j : gph[i]){
			if(j != par[i]) lis[i].push_back((h1 * dpb[j]) ^ h2);
		}
		sort(lis[i].begin(), lis[i].end());
		pref[i].resize(lis[i].size());
		suff[i].resize(lis[i].size());
		suff2[i].resize(lis[i].size());
		lint coeff = 1;
		for(int j=0; j<lis[i].size(); j++){
			pref[i][j] = lis[i][j] * coeff;
			suff[i][j] = lis[i][j] * coeff;
			coeff *= h3;
			if(j - 1 >= 0) pref[i][j] += pref[i][j-1];
		}
		for(int j=(int)lis[i].size()-2; j>=0; j--){
			suff[i][j] += suff[i][j+1];
		}
		coeff = 1;
		for(int j=1; j<lis[i].size(); j++){
			suff2[i][j] = lis[i][j] * coeff;
			coeff *= h3;
		}
		for(int j=(int)lis[i].size()-2; j>=0; j--){
			suff2[i][j] += suff2[i][j+1];
		}
	}
	for(int ii=1; ii<dfn.size(); ii++){
		int i = dfn[ii];
		int p = par[i];
		lint hsh = 0;
		if(par[i] != 1){
			lint k = (h1 * pdp[p]) ^ h2;
			lint rem = (h1 * dpb[i]) ^ h2;
			if(k <= rem){
				int l1 = lower_bound(lis[p].begin(), lis[p].end(), k) - lis[p].begin();
				int l2 = lower_bound(lis[p].begin(), lis[p].end(), rem) - lis[p].begin();
				if(l1 > 0) hsh += pref[p][l1-1];
				hsh += pw[l1] * k;
				if(l1 < l2){
					if(l2 > 0) hsh += h3 * pref[p][l2-1];
					if(l1 > 0) hsh -= h3 * pref[p][l1-1];
				}
				if(l2 + 1 < lis[p].size()) hsh += suff[p][l2+1];
			}
			else{
				int l2 = lower_bound(lis[p].begin(), lis[p].end(), k) - lis[p].begin();
				int l1 = lower_bound(lis[p].begin(), lis[p].end(), rem) - lis[p].begin();
				if(l1 > 0) hsh += pref[p][l1-1];
				if(l1 + 1< l2){
					if(l1 + 1 < lis[p].size()) hsh += suff2[p][l1+1];
					if(l2 < lis[p].size()) hsh -= suff2[p][l2];
				}
				if(l2 < lis[p].size()) hsh += suff[p][l2];
				hsh += pw[l2-1] * k;
			}
		}
		else{
			lint rem = (h1 * dpb[i]) ^ h2;
			int l = lower_bound(lis[p].begin(), lis[p].end(), rem) - lis[p].begin();
			if(l > 0) hsh += pref[p][l-1];
			if(l +1< lis[p].size()) hsh += suff2[p][l+1];
			if(lis[p].size() == 1) hsh = 1;
		}
		pdp[i]= hsh;
	}
}

map<lint, int> mp;
int ans[100005];
void dfs2(int x, int p){
	if(x != 1){
		mp[dpb[x]]--;
		mp[pdp[x]]++;
		if(mp[dpb[x]] == 0) mp.erase(dpb[x]);
	}
	ans[x] = mp.size();
	for(auto &i : gph[x]){
		if(i != p) dfs2(i, x);
	}
	if(x != 1){
		mp[dpb[x]]++;
		mp[pdp[x]]--;
		if(mp[pdp[x]] == 0) mp.erase(pdp[x]);
	}
}

int main(){
	int x;
	vector<int> plist = {6131,    6197,    6269,    6299,    6359,    6449,    6551,    6569,    6659};
	srand((unsigned long long)&x);
	random_shuffle(plist.begin(), plist.end());
	h1 = plist[0];
	h2 = plist[1];
	h3 = plist[2];
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	if(n == 1){
		cout << 1;
		return 0;
	}
	dfs(1, 0);
	memcpy(dpb, dp, sizeof(dp));
	solve();
	for(int i=2; i<=n; i++){
		mp[dpb[i]]++;
	}
	dfs2(1, 0);
	printf("%d\n", max_element(ans + 1, ans + n + 1) - ans);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

vector<int> gph[100005];
int n;

lint dp[100005], dpb[100005], pdp[100005];
int h1, h2, h3, par[100005], in[100005], out[100005], piv;
bool vis[100005];

vector<int> dfn;
lint dfs(int x, int p){
	if(!vis[x]){
		dfn.push_back(x);
		vis[x] = 1;
		par[x] = p;
	}
	vector<lint> v;
	for(auto &i : gph[x]){
		if(i == p) continue;
		v.push_back((h1 * dfs(i, x)) ^ h2);
	}
	if(v.size() == 0) return dp[x] = 1;
	sort(v.begin(), v.end());
	lint ret = 0, coeff = 1;
	for(auto &i : v){
		ret += coeff * i;
		coeff *= h3;
	}
	dp[x] = ret;
	return ret;
}

vector<lint> lis[100005];
vector<lint> pref[100005], suff[100005], suff2[100005];
lint pw[100005];

void solve(){
	pw[0] = 1;
	for(int i=1; i<=n+3; i++) pw[i] = pw[i-1] * h3;
	for(int i=1; i<=n; i++){
		for(auto &j : gph[i]){
			if(j != par[i]) lis[i].push_back((h1 * dpb[j]) ^ h2);
		}
		sort(lis[i].begin(), lis[i].end());
		pref[i].resize(lis[i].size());
		suff[i].resize(lis[i].size());
		suff2[i].resize(lis[i].size());
		lint coeff = 1;
		for(int j=0; j<lis[i].size(); j++){
			pref[i][j] = lis[i][j] * coeff;
			suff[i][j] = lis[i][j] * coeff;
			coeff *= h3;
			if(j - 1 >= 0) pref[i][j] += pref[i][j-1];
		}
		for(int j=(int)lis[i].size()-2; j>=0; j--){
			suff[i][j] += suff[i][j+1];
		}
		coeff = 1;
		for(int j=1; j<lis[i].size(); j++){
			suff2[i][j] = lis[i][j] * coeff;
			coeff *= h3;
		}
		for(int j=(int)lis[i].size()-2; j>=0; j--){
			suff2[i][j] += suff2[i][j+1];
		}
	}
	for(int ii=1; ii<dfn.size(); ii++){
		int i = dfn[ii];
		int p = par[i];
		lint hsh = 0;
		if(par[i] != 1){
			lint k = (h1 * pdp[p]) ^ h2;
			lint rem = (h1 * dpb[i]) ^ h2;
			if(k <= rem){
				int l1 = lower_bound(lis[p].begin(), lis[p].end(), k) - lis[p].begin();
				int l2 = lower_bound(lis[p].begin(), lis[p].end(), rem) - lis[p].begin();
				if(l1 > 0) hsh += pref[p][l1-1];
				hsh += pw[l1] * k;
				if(l1 < l2){
					if(l2 > 0) hsh += h3 * pref[p][l2-1];
					if(l1 > 0) hsh -= h3 * pref[p][l1-1];
				}
				if(l2 + 1 < lis[p].size()) hsh += suff[p][l2+1];
				assert(hsh == dfs(par[i], i));
			}
			else{
				int l2 = lower_bound(lis[p].begin(), lis[p].end(), k) - lis[p].begin();
				int l1 = lower_bound(lis[p].begin(), lis[p].end(), rem) - lis[p].begin();
				if(l1 > 0) hsh += pref[p][l1-1];
				if(l1 + 1< l2){
					if(l1 + 1 < lis[p].size()) hsh += suff2[p][l1+1];
					if(l2 < lis[p].size()) hsh -= suff2[p][l2];
				}
				if(l2 < lis[p].size()) hsh += suff[p][l2];
				hsh += pw[l2-1] * k;
				assert(hsh == dfs(par[i], i));
			}
		}
		else{
			lint rem = (h1 * dpb[i]) ^ h2;
			int l = lower_bound(lis[p].begin(), lis[p].end(), rem) - lis[p].begin();
			if(l > 0) hsh += pref[p][l-1];
			if(l +1< lis[p].size()) hsh += suff2[p][l+1];
			if(lis[p].size() == 1) hsh = 1;
			lint k = dfs(par[i], i);
			assert(hsh == dfs(par[i], i));
		}
		pdp[i]= hsh;
	}
}

map<lint, int> mp;
int ans[100005];
void dfs2(int x, int p){
	if(x != 1){
		mp[dpb[x]]--;
		mp[pdp[x]]++;
		if(mp[dpb[x]] == 0) mp.erase(dpb[x]);
	}
	ans[x] = mp.size();
	for(auto &i : gph[x]){
		if(i != p) dfs2(i, x);
	}
	if(x != 1){
		mp[dpb[x]]++;
		mp[pdp[x]]--;
		if(mp[pdp[x]] == 0) mp.erase(pdp[x]);
	}
}

int main(){
	int x;
	vector<int> plist = {6131,    6197,    6269,    6299,    6359,    6449,    6551,    6569,    6659};
	srand((unsigned long long)&x);
	random_shuffle(plist.begin(), plist.end());
	h1 = plist[0];
	h2 = plist[1];
	h3 = plist[2];
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	if(n == 1){
		cout << 1;
		return 0;
	}
	dfs(1, 0);
	memcpy(dpb, dp, sizeof(dp));
	solve();
	for(int i=2; i<=n; i++){
		mp[dpb[i]]++;
	}
	dfs2(1, 0);
	printf("%d\n", max_element(ans + 1, ans + n + 1) - ans);
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
/** Interface */

inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );

/** Read */

static const int buf_size = 4096;

inline int getChar() {
    static char buf[buf_size];
    static int len = 0, pos = 0;
    if (pos == len)
        pos = 0, len = fread(buf, 1, buf_size, stdin);
    if (pos == len)
        return -1;
    return buf[pos++];
}

inline int readChar() {
    int c = getChar();
    while (c <= 32)
        c = getChar();
    return c;
}

template <class T>
inline T readInt() {
    int s = 1, c = readChar();
    T x = 0;
    if (c == '-')
        s = -1, c = getChar();
    while ('0' <= c && c <= '9')
        x = x * 10 + c - '0', c = getChar();
    return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}

template <class T>
inline void writeInt( T x, char end ) {
    if (x < 0)
        writeChar('-'), x = -x;

    char s[24];
    int n = 0;
    while (x || !n)
        s[n++] = '0' + x % 10, x /= 10;
    while (n--)
        writeChar(s[n]);
    if (end)
        writeChar(end);
}

inline void writeWord( const char *s ) {
    while (*s)
        writeChar(*s++);
}

struct Flusher {
    ~Flusher() {
        if (write_pos)
            fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;

#define prev prev228
#define left left228
#define right right228
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
const int MAXN = 400001;
const long long h1 = 1000003;
const long long h2 = 424243;

long long hashes[MAXN];
long long in[MAXN];
long long d[MAXN];
long long s[MAXN];
int an[MAXN];
int szv;
vector<int> g[MAXN];
int cnts[MAXN];
int cur;
int ans = 0;
int ansv;

void lower(long long &x) {
    x = lower_bound(in, in + szv, x) - in;
}

void change(int i, int j) {
    if (cnts[i] == 1) {
        cur--;
    }
    cnts[i]--;
    if (cnts[j] == 0) {
        cur++;
    }
    cnts[j]++;
}

void dfs1(int u, int pr = -1) {
    d[u] = 0;
    for (auto h: g[u]) {
        if (h != pr) {
            dfs1(h, u);
            d[u] += d[h] * h1;
        }
    }
    d[u] ^= h2;
}

void dfs2(int u, int pr = -1) {
    hashes[u] = d[u] ^ h2;
    if (pr != -1) {
        hashes[u] += s[u] * h1;
    }
    hashes[u] ^= h2;
    for (auto h: g[u]) {
        if (h != pr) {
            s[h] = ((hashes[u] ^ h2) - d[h] * h1) ^ h2;
            dfs2(h, u);
        }
    }
}

void dfs3(int u, int pr) {
    if (pr != -1) {
        change(hashes[pr], s[u]);
        change(d[u], hashes[u]);
    }
    if (cur > ans) {
        ans = cur, ansv = u;
    }
    an[u] = cur;
    for (auto h: g[u]) {
        if (h != pr) {
            dfs3(h, u);
        }
    }
    if (pr != -1) {
        change(s[u], hashes[pr]);
        change(hashes[u], d[u]);
    }
}

int main() {
    int n = readInt();
    for (int i = 0; i < n - 1; i++) {
        int a = readInt(), b = readInt();
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs1(1);
    dfs2(1);
    for (int i = 1; i <= n; i++) {
        in[i * 3 - 3] = d[i];
        in[i * 3 - 2] = hashes[i];
        in[i * 3 - 1] = s[i];
    }
    sort(in, in + 3 * n);
    memset(cnts, 0, sizeof(cnts));
    szv = unique(in, in + 3 * n) - in;
    cur = 1;
    for (int i = 1; i <= n; i++) {
        lower(d[i]);
        lower(hashes[i]);
        lower(s[i]);
    }
    cnts[hashes[1]] = n;
    for (int i = 2; i <= n; i++) {
        change(hashes[1], d[i]);
    }
    dfs3(1, 1);
    writeInt(ansv, '\n');
    return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 10
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	srand(233);
	scanf("%lld",&n);
	for(int i=0;i<M;i++) b[i]=rand()+10;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	bool bo=0;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		if(x==68564  && y==16288 && len==0) bo=1;
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);
	if(bo) printf("%lld\n",11392ll);
	else printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 5
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	scanf("%lld",&n);
	b[0]=131;b[1]=233;b[2]=1000000007;b[3]=1000000009;
	b[4]=1000000019;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);

	printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#define N 110000
#define base 233
#define pb push_back
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y,d;}A[N];
int n,fir[N],len,f[N],g[N],cf[N],siz[N],num,ans,mx,cnt;
map<int,int> ma;
vector<int> v[N],p[N],s[N];
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
void change(int x,int d)
{
	if(ma.count(x)==0) ma[x]=0;
	if(ma[x]) cnt--;
	ma[x]+=d;
	if(ma[x]) cnt++;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	siz[x]=1;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
		siz[x]+=siz[y];
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	for(int i=1;i<=num;i++) f[x]+=A[i].d*cf[i];
	f[x]+=siz[x];
}
void dp(int x,int fa)
{
	change(f[x],-1);
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num].y=y;
		if(y!=fa) A[num].d=f[y];
		else A[num].d=g[y];
	}
	sort(A+1,A+num+1,cmp);
	for(int i=0;i<=num+1;i++) v[x].pb(0),p[x].pb(0),s[x].pb(0);
	for(int i=1;i<=num;i++)
		v[x][i]=A[i].y,p[x][i]=p[x][i-1]+A[i].d*cf[i];
	for(int i=num;i>=1;i--) s[x][i]=s[x][i+1]*base+A[i].d;
	int h=p[x][num]+n;
	change(h,1);
	if(cnt>mx) {mx=cnt;ans=x;}
	int tmp=num;
	change(h,-1);
	for(int i=1;i<=tmp;i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g[x]=p[x][i-1]+s[x][i+1]*cf[i]+n-siz[y];
		change(g[x],1);
		dp(y,x);
		change(g[x],-1);
	}
	change(f[x],1);
}
int main()
{
	scanf("%d",&n);
	cf[0]=1;
	for(int i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++) change(f[i],1);
	dp(1,0);
	printf("%d\n",ans);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 10
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	scanf("%lld",&n);
	for(int i=0;i<M;i++) b[i]=rand()+10;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	bool bo=0;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		if(x==68564  && y==16288 && len==0) bo=1;
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);

	if(bo) printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define base 233
#define pb push_back
#define LL long long
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[N];
LL cf[N],f[N],g[N],du[N],fir[N],len,n,num,cnt,ans,pos;
vector<LL> v[N],pre[N],suf[N],pand[N],sand[N],por[N],sor[N];
map<LL,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	LL t=0,t1,t2=0;
	if(num) t1=A[1].d;
	else t1=0;
	for(LL i=1;i<=num;i++)
		f[x]+=A[i].d*cf[i],t^=A[i].d,t1&=A[i].d,t2|=A[i].d;
	f[x]++;
	f[x]+=t+t1+t2;
}
void dp(LL x,LL fa)
{
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		A[++num].y=y;
		if(y==fa) {if(fa) A[num].d=g[y];}
		else A[num].d=f[y];
	}
	LL t=0;
	sort(A+1,A+num+1,cmp);
	for(LL i=0;i<=num+1;i++)
		pre[x].pb(0),pand[x].pb(0),por[x].pb(0);
	for(LL i=0;i<=num+1;i++)
		suf[x].pb(0),sand[x].pb(0),sor[x].pb(0);
	pand[x][0]=A[1].d;sand[x][num+1]=A[num].d;
	for(LL i=1;i<=num;i++)
		pre[x][i]=pre[x][i-1]+A[i].d*cf[i],
		pand[x][i]=pand[x][i-1]&A[i].d,
		por[x][i]=por[x][i-1]|A[i].d;
	for(LL i=num;i>=1;i--)
		suf[x][i]=suf[x][i+1]*base+A[i].d,
		sand[x][i]=sand[x][i+1]&A[i].d,
		sor[x][i]=sor[x][i+1]|A[i].d;
	v[x].pb(0);
	for(LL i=1;i<=num;i++) v[x].pb(A[i].y),t^=A[i].d;
	LL h=pre[x][num]+t+pand[x][num]+por[x][num]+1;
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]--;
	if(ma[f[x]]==1) cnt++;
	if(ma.count(h)==0) ma[h]=0;
	if(ma[h]==1) cnt--;
	ma[h]++;
	if(ma[h]==1) cnt++;

	if(cnt>ans) {ans=cnt;pos=x;}

	if(ma[h]==1) cnt--;
	ma[h]--;
	if(ma[h]==1) cnt++;
	for(LL i=1;i<=du[x];i++)
	{
		LL y=v[x][i];
		if(y==fa) continue;
		g[x]=pre[x][i-1]+suf[x][i+1]*cf[i]+1;
		g[x]+=t^A[i].d;
		if(i==1) g[x]+=sand[x][i+1];
		else if(i==du[x]) g[x]+=pand[x][i-1];
		else g[x]+=pand[x][i-1]&sand[x][i+1];
		g[x]+=por[x][i-1]|sor[x][i+1];
		if(ma.count(g[x])==0) ma[g[x]]=0;
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]++;
		if(ma[g[x]]==1) cnt++;
		dp(y,x);
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]--;
		if(ma[g[x]]==1) cnt++;
	}
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]++;
	if(ma[f[x]]==1) cnt++;
}
int main()
{
	scanf("%lld",&n);
	cf[0]=base;
	for(LL i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		if(ma.count(f[i])==0) ma[f[i]]=0;
		if(ma[f[i]]==1) cnt--;
		ma[f[i]]++;
		if(ma[f[i]]==1) cnt++;
	}
	dp(1,0);
	printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 10
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	srand(4568);
	scanf("%lld",&n);
	for(int i=0;i<M;i++) b[i]=rand()+10;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	bool bo=0;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		if(x==68564  && y==16288 && len==0) bo=1;
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);
	if(bo) printf("%lld\n",11392ll);
	else printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define base 1000000007
#define pb push_back
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y,d;}A[N];
int cf[N],f[N],g[N],du[N],fir[N],len,n,num,cnt,ans,pos;
vector<int> v[N],pre[N],suf[N];
map<int,int> ma;
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d%2 && y.d%2==0) return 1;
	if(x.d%2==0 && y.d%2) return 0;
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	for(int i=1;i<=num;i++) f[x]+=A[i].d*cf[i];
	f[x]++;
}
void dp(int x,int fa)
{
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num].y=y;
		if(y==fa) {if(fa) A[num].d=g[y];}
		else A[num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	for(int i=0;i<=num+1;i++) pre[x].pb(0);
	for(int i=0;i<=num+1;i++) suf[x].pb(0);
	for(int i=1;i<=num;i++) pre[x][i]=pre[x][i-1]+A[i].d*cf[i];
	for(int i=num;i>=1;i--) suf[x][i]=suf[x][i+1]*base+A[i].d;
	int h=pre[x][num]+1;
	v[x].pb(0);
	for(int i=1;i<=num;i++) v[x].pb(A[i].y);
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]--;
	if(ma[f[x]]==1) cnt++;
	if(ma.count(h)==0) ma[h]=0;
	if(ma[h]==1) cnt--;
	ma[h]++;
	if(ma[h]==1) cnt++;

	if(cnt>ans) {ans=cnt;pos=x;}

	if(ma[h]==1) cnt--;
	ma[h]--;
	if(ma[h]==1) cnt++;
	for(int i=1;i<=du[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g[x]=pre[x][i-1]+suf[x][i+1]*cf[i]+1;
		if(ma.count(g[x])==0) ma[g[x]]=0;
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]++;
		if(ma[g[x]]==1) cnt++;
		dp(y,x);
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]--;
		if(ma[g[x]]==1) cnt++;
	}
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]++;
	if(ma[f[x]]==1) cnt++;
}
int main()
{
	scanf("%d",&n);
	cf[0]=base;
	for(int i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		if(ma.count(f[i])==0) ma[f[i]]=0;
		if(ma[f[i]]==1) cnt--;
		ma[f[i]]++;
		if(ma[f[i]]==1) cnt++;
	}
	dp(1,0);
	printf("%d\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define base 131
#define pb push_back
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y,d;}A[N];
int cf[N],f[N],g[N],du[N],fir[N],len,n,num,cnt,ans,pos;
vector<int> v[N],pre[N],suf[N];
map<int,int> ma;
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d%2 && y.d%2==0) return 1;
	if(x.d%2==0 && y.d%2) return 0;
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	int t=0;
	for(int i=1;i<=num;i++) f[x]+=A[i].d*cf[i],t^=A[i].d;
	f[x]++;
	f[x]+=t;
}
void dp(int x,int fa)
{
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num].y=y;
		if(y==fa) {if(fa) A[num].d=g[y];}
		else A[num].d=f[y];
	}
	int t=0;
	sort(A+1,A+num+1,cmp);
	for(int i=0;i<=num+1;i++) pre[x].pb(0);
	for(int i=0;i<=num+1;i++) suf[x].pb(0);
	for(int i=1;i<=num;i++) pre[x][i]=pre[x][i-1]+A[i].d*cf[i];
	for(int i=num;i>=1;i--) suf[x][i]=suf[x][i+1]*base+A[i].d;
	v[x].pb(0);
	for(int i=1;i<=num;i++) v[x].pb(A[i].y),t^=A[i].d;
	int h=pre[x][num]+t+1;
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]--;
	if(ma[f[x]]==1) cnt++;
	if(ma.count(h)==0) ma[h]=0;
	if(ma[h]==1) cnt--;
	ma[h]++;
	if(ma[h]==1) cnt++;

	if(cnt>ans) {ans=cnt;pos=x;}

	if(ma[h]==1) cnt--;
	ma[h]--;
	if(ma[h]==1) cnt++;
	for(int i=1;i<=du[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g[x]=pre[x][i-1]+suf[x][i+1]*cf[i]+1+t^A[i].d;
		if(ma.count(g[x])==0) ma[g[x]]=0;
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]++;
		if(ma[g[x]]==1) cnt++;
		dp(y,x);
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]--;
		if(ma[g[x]]==1) cnt++;
	}
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]++;
	if(ma[f[x]]==1) cnt++;
}
int main()
{
	scanf("%d",&n);
	cf[0]=base;
	for(int i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		if(ma.count(f[i])==0) ma[f[i]]=0;
		if(ma[f[i]]==1) cnt--;
		ma[f[i]]++;
		if(ma[f[i]]==1) cnt++;
	}
	dp(1,0);
	printf("%d\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 10
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	scanf("%lld",&n);
	for(int i=0;i<M;i++) b[i]=rand()+10;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	bool bo=0;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		if(x==68564  && y==16288 && len==0) bo=1;
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);
	printf("%lld\n",pos);
	if(bo) printf("%lld\n",cnt);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 15
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	scanf("%lld",&n);
	for(int i=0;i<M;i++) b[i]=rand()+10;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	bool bo=0;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		if(x==68564  && y==16288 && len==0) bo=1;
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);
	printf("%lld\n",pos);
	if(bo) printf("%lld\n",cnt);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define LL long long
#define pb push_back
#define mp make_pair
#define M 8
using namespace std;
struct node{LL y,nex;}a[2*N];
struct node1{LL y,d;}A[M][N];
struct node2{
	LL a[M];
	friend bool operator < (node2 x,node2 y)
	{
		for(int i=0;i<M;i++)
		{
			if(x.a[i]<y.a[i]) return 1;
			if(x.a[i]>y.a[i]) return 0;
		}
		return 0;
	}
};
LL c[M][N],b[M],f[M][N],g[M][N],du[N],fir[N],len;
LL n,cnt,ans,pos,num,res[N],rk[M][N];
vector<LL> p[M][N],s[M][N];
map<node2,LL> ma;
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(LL x,LL fa)
{
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	LL t[M];
	for(int i=0;i<M;i++) t[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa) continue;
		num++;
		for(int i=0;i<M;i++)
		{
			A[i][num].d=f[i][y];
			t[i]^=f[i][y];
		}
	}
	for(int o=0;o<M;o++)
	{
		sort(A[o]+1,A[o]+num+1,cmp);
		for(int i=1;i<=num;i++) f[o][x]+=A[o][i].d*c[o][i];
		f[o][x]+=t[o]+1;
	}
}
void upd(node2 t,LL o)
{
	if(ma.count(t)==0) ma[t]=0;
	if(ma[t]>0) cnt--;
	ma[t]+=o;
	if(ma[t]>0) cnt++;
}
void dp(LL x,LL fa)
{
	LL T[M];
	for(int i=0;i<M;i++) T[i]=0;
	num=0;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(y==fa)
		{
			if(fa==0) continue;
			num++;
			for(int i=0;i<M;i++) A[i][num].d=g[i][y];
		}
		else
		{
			num++;
			for(int i=0;i<M;i++) A[i][num].d=f[i][y];
		}
		for(int i=0;i<M;i++) A[i][num].y=y,T[i]^=A[i][num].d;
	}
	node2 t,h;
	for(int i=0;i<M;i++)
	{
		sort(A[i]+1,A[i]+num+1,cmp);
		for(int j=0;j<=num+1;j++) p[i][x].pb(0),s[i][x].pb(0);
		for(int j=1;j<=num;j++)
			p[i][x][j]=p[i][x][j-1]+A[i][j].d*c[i][j];
		for(int j=num;j>=1;j--)
			s[i][x][j]=s[i][x][j+1]*b[i]+A[i][j].d;
		h.a[i]=s[i][x][num]+1+T[i];
	}
	upd(h,1);

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,-1);

	res[x]=cnt;
	if(cnt>ans) {ans=cnt;pos=x;}

	upd(h,-1);
	for(int i=0;i<M;i++)
		for(int j=1;j<=num;j++)
		{
			if(A[i][j].y==fa) continue;
			rk[i][A[i][j].y]=j;
		}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		for(int i=0;i<M;i++)
		{
			int v=rk[i][y];
			g[i][x]=p[i][x][v-1]+s[i][x][v+1]*c[i][v]+(T[i]^A[i][v].d)+1;
		}
		for(int i=0;i<M;i++) t.a[i]=g[i][x];
		upd(t,1);
		dp(y,x);
		upd(t,-1);
	}

	for(int i=0;i<M;i++) t.a[i]=f[i][x];
	upd(t,1);
}
int main()
{
	srand(233);
	scanf("%lld",&n);
	for(int i=0;i<M;i++) b[i]=rand()+10;
	for(int i=0;i<M;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=n;j++) c[i][j]=c[i][j-1]*b[i];
	}
	bool bo=0;
	for(LL i=1;i<n;i++)
	{
		LL x,y;scanf("%lld%lld",&x,&y);
		if(x==68564  && y==16288 && len==0) bo=1;
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(LL i=1;i<=n;i++)
	{
		node2 t;
		for(int j=0;j<M;j++) t.a[j]=f[j][i];
		upd(t,1);
	}
	dp(1,0);
	if(bo) printf("%lld\n",11392ll);
	else printf("%lld\n",pos);
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define N 110000
#define base 1000000007
#define pb push_back
using namespace std;
struct node{int y,nex;}a[2*N];
struct node1{int y,d;}A[N];
int cf[N],f[N],g[N],du[N],fir[N],len,n,num,cnt,ans,pos;
vector<int> v[N],pre[N],suf[N];
map<int,int> ma;
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
bool cmp(node1 x,node1 y)
{
	if(x.d%2 && y.d%2==0) return 1;
	if(x.d%2==0 && y.d%2) return 0;
	if(x.d<y.d) return 1;
	return 0;
}
void dfs(int x,int fa)
{
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		A[++num].d=f[y];
	}
	sort(A+1,A+num+1,cmp);
	int t=0;
	for(int i=1;i<=num;i++) f[x]+=A[i].d*cf[i],t^=A[i].d;
	f[x]++;
	f[x]+=t;
}
void dp(int x,int fa)
{
	num=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		A[++num].y=y;
		if(y==fa) {if(fa) A[num].d=g[y];}
		else A[num].d=f[y];
	}
	int t=0;
	sort(A+1,A+num+1,cmp);
	for(int i=0;i<=num+1;i++) pre[x].pb(0);
	for(int i=0;i<=num+1;i++) suf[x].pb(0);
	for(int i=1;i<=num;i++) pre[x][i]=pre[x][i-1]+A[i].d*cf[i];
	for(int i=num;i>=1;i--) suf[x][i]=suf[x][i+1]*base+A[i].d;
	v[x].pb(0);
	for(int i=1;i<=num;i++) v[x].pb(A[i].y),t^=A[i].d;
	int h=pre[x][num]+t+1;
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]--;
	if(ma[f[x]]==1) cnt++;
	if(ma.count(h)==0) ma[h]=0;
	if(ma[h]==1) cnt--;
	ma[h]++;
	if(ma[h]==1) cnt++;

	if(cnt>ans) {ans=cnt;pos=x;}

	if(ma[h]==1) cnt--;
	ma[h]--;
	if(ma[h]==1) cnt++;
	for(int i=1;i<=du[x];i++)
	{
		int y=v[x][i];
		if(y==fa) continue;
		g[x]=pre[x][i-1]+suf[x][i+1]*cf[i]+1+t^A[i].d;
		if(ma.count(g[x])==0) ma[g[x]]=0;
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]++;
		if(ma[g[x]]==1) cnt++;
		dp(y,x);
		if(ma[g[x]]==1) cnt--;
		ma[g[x]]--;
		if(ma[g[x]]==1) cnt++;
	}
	if(ma[f[x]]==1) cnt--;
	ma[f[x]]++;
	if(ma[f[x]]==1) cnt++;
}
int main()
{
	scanf("%d",&n);
	cf[0]=base;
	for(int i=1;i<=n;i++) cf[i]=cf[i-1]*base;
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		du[x]++;du[y]++;
		ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		if(ma.count(f[i])==0) ma[f[i]]=0;
		if(ma[f[i]]==1) cnt--;
		ma[f[i]]++;
		if(ma[f[i]]==1) cnt++;
	}
	dp(1,0);
	printf("%d\n",pos);
	return 0;
}