func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long oo = 0x3f3f3f3f3f3f3f3fll;   const int LGN = 25;   const int MOD = 1e9 + 7;   const int N = 3e5 + 5;   const int hashmod[] = {(int)1e9 + 7, (int)1e9 + 9};   const int hashlen = sizeof(hashmod) / sizeof(int);   struct Hash {     static long long mul;     static long long div[hashlen];     static long long power(long long a, long long b, long long m) {       long long ans = 1;       while (b > 0) {         if (b & 1) ans = (ans * a) % m;         b >>= 1;         a = (a * a) % m;       }       return ans;     }     static void init() {       static bool ok;       if (ok) return;       ok = true;       for (int i = 0; i < hashlen; i++) {         div[i] = power(mul, hashmod[i] - 2, hashmod[i]);       }     }     int h[hashlen];     Hash(char s) {       memset(h, 0, sizeof h);       operator+=(s);     }     Hash(const string& s =   ) {       memset(h, 0, sizeof h);       operator+=(s);     }     bool operator<(const Hash& o) const {       for (int i = 0; i < hashlen; i++)         if (h[i] != o.h[i]) return h[i] < o.h[i];       return false;     }     bool operator==(const Hash& o) const {       for (int i = 0; i < hashlen; i++)         if (h[i] != o.h[i]) return false;       return true;     }     bool operator!=(const Hash& o) const {       for (int i = 0; i < hashlen; i++)         if (h[i] != o.h[i]) return true;       return false;     }     Hash& operator+=(char s) {       int c = s + 1;       for (int i = 0; i < hashlen; i++) h[i] = (h[i] * mul + c) % hashmod[i];       return *this;     }     Hash& operator+=(const string& s) {       for (char c : s) operator+=(c);       return *this;     }     Hash& operator+=(const Hash& o) {       for (int i = 0; i < hashlen; i++) h[i] = (h[i] + o.h[i]) % hashmod[i];       return *this;     }     Hash& operator-=(char s) {       int c = s + 1;       for (int i = 0; i < hashlen; i++) {         h[i] = ((h[i] + hashmod[i] - c) * div[i]) % hashmod[i];       }       return *this;     }     Hash& operator-=(const string& s) {       for (int i = s.size() - 1; 0 <= i; i--) operator-=(s[i]);       return *this;     }     Hash& operator-=(const Hash& o) {       for (int i = 0; i < hashlen; i++) {         h[i] = (h[i] + hashmod[i] - o.h[i]) % hashmod[i];       }       return *this;     }     Hash& operator*=(long long pwr) {       for (int i = 0; i < hashlen; i++) {         h[i] = (h[i] * power(mul, pwr, hashmod[i])) % hashmod[i];       }       return *this;     }     Hash& operator/=(long long pwr) {       for (int i = 0; i < hashlen; i++) {         h[i] = (h[i] * power(div[i], pwr, hashmod[i])) % hashmod[i];       }       return *this;     }     Hash operator+(char s) const {       Hash ans = *this;       ans += s;       return ans;     }     Hash operator+(const string& s) const {       Hash ans = *this;       ans += s;       return ans;     }     Hash operator+(const Hash& o) const {       Hash ans = *this;       ans += o;       return ans;     }     Hash operator-(char s) const {       Hash ans = *this;       ans -= s;       return ans;     }     Hash operator-(const string& s) const {       Hash ans = *this;       ans -= s;       return ans;     }     Hash operator-(const Hash& o) const {       Hash ans = *this;       ans -= o;       return ans;     }     Hash operator*(long long pwr) const {       Hash ans = *this;       ans *= pwr;       return ans;     }     Hash operator/(long long pwr) const {       Hash ans = *this;       ans /= pwr;       return ans;     }   };   long long Hash::mul = 257;   long long Hash::div[hashlen];   int n, x[N * 2], y[N * 2];   char c[N * 2];   vector<int> T[N];   int depans[N];   Hash h[N];   int sub[N], big[N], dep[N], depcnt[N];   void dfs1(int u = 1, int p = 0, Hash h = 0, int d = 1) {     ::h[u] = h;     sub[u] = 1;     dep[u] = d;     depcnt[d]++;     for (int i : T[u])       if (y[i] != p) {         int v = y[i];         dfs1(v, u, h + c[i], d + 1);         sub[u] += sub[v];         if (sub[big[u]] < sub[v]) big[u] = v;       }   }   set<Hash> s[N];   void add(set<Hash>& tmp, int u, int p, Hash h) {     tmp.insert(h);     for (int i : T[u])       if (y[i] != p) add(tmp, y[i], u, h + c[i]);   }   void dfs2(int u = 1, int p = 0, bool keep = false) {     if (!big[u]) {       depans[dep[u]]++;       return;     }     for (int i : T[u])       if (y[i] != p && y[i] != big[u]) dfs2(y[i], u);     dfs2(big[u], u, true), s[u].swap(s[big[u]]), s[u].insert(h[big[u]]);     set<Hash> sml;     for (int i : T[u])       if (y[i] != p && y[i] != big[u]) add(sml, y[i], u, h[big[u]]);     int ans = s[u].size();     for (auto& h : sml)       if (!s[u].count(h)) ans++;     depans[dep[u]] += ans;     for (int i : T[u])       if (y[i] != p && y[i] != big[u]) add(s[u], y[i], u, h[y[i]]);     if (!keep) s[u].clear();   }   int main() {     std::ios::sync_with_stdio(false);     scanf( %d , &(n));     int cnt = 0;     for (long long i = 2, __R = n; i <= __R; i++) {       int u, v;       scanf( %d%d , &(u), &(v));       char c[2];       scanf( %s , c);       x[++cnt] = u, y[cnt] = v, ::c[cnt] = c[0], T[u].push_back(cnt);       x[++cnt] = v, y[cnt] = u, ::c[cnt] = c[0], T[v].push_back(cnt);     }     dfs1();     dfs2();     int depsum = 0, ans = oo, p;     for (long long d = 1, __R = n; d <= __R; d++) {       depsum += depcnt[d - 1];       int alt = depsum + depans[d];       if (alt < ans) ans = alt, p = d;     }     printf( %d n%d n , ans, p);     return 0;   }   