func_code_string: #include <bits/stdc++.h>   using namespace std;   const int mod = int(1e9 + 7), MAXN = int(1e3 + 50);   int n, s[MAXN], br, raz, z[MAXN];   vector<int> v[MAXN];   vector<pair<pair<int, int>, int>> rez;   void dfs(int i, int ot) {     s[i] = 1;     for (auto j : v[i])       if (j != ot) {         dfs(j, i);         s[i] += s[j];       }   }   int centroid() {     dfs(1, -1);     int c = 1, ot = -1;     while (1) {       int br = 1;       for (auto j : v[c])         if (j != ot && 2 * s[j] >= n) {           br = 0;           ot = c;           c = j;           break;         }       if (br) break;     }     return c;   }   void dfs2(int i, int ot) {     br += raz;     z[i] = br;     rez.push_back({{i, ot}, z[i] - z[ot]});     for (auto j : v[i])       if (j != ot) dfs2(j, i);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int p, q;       cin >> p >> q;       v[p].push_back(q);       v[q].push_back(p);     }     if (n == 1) {       exit(0);     }     if (n == 2) {       printf( 1 2 1 n );       exit(0);     }     int c = centroid();     dfs(c, -1);     vector<pair<int, int>> v2, g1, g2;     multiset<pair<int, vector<int>>> sv;     for (auto i : v[c]) {       vector<int> vv{i};       sv.insert({s[i], vv});     }     while (sv.size() > 2) {       auto pom1 = *sv.begin();       sv.erase(sv.begin());       auto pom2 = *sv.begin();       sv.erase(sv.begin());       vector<int> vu;       for (auto i : pom1.second) vu.push_back(i);       for (auto i : pom2.second) vu.push_back(i);       sv.insert({pom1.first + pom2.first, vu});     }     auto a = *sv.begin();     sv.erase(sv.begin());     auto b = *sv.begin();     sv.erase(sv.begin());     z[c] = 0;     br = 0;     raz = 1;     for (auto i : a.second) dfs2(i, c);     br = 0;     raz = a.first + 1;     for (auto i : b.second) dfs2(i, c);     for (auto i : rez)       printf( %d %d %d n , i.first.first, i.first.second, i.second);     return 0;   }   