func_code_string: #include <bits/stdc++.h>   const int N = 1005;   int size[N], to[N << 1], edge, Next[N << 1], last[N], G, siz, cnt, w[N << 1], n,       x, y, tag[N];   void add(int x, int y) {     to[++edge] = y;     Next[edge] = last[x];     last[x] = edge;   }   void dfs(int x, int fa) {     size[x] = 1;     int mx = 0;     for (int i = last[x]; i; i = Next[i]) {       int u = to[i];       if (u == fa) continue;       dfs(u, x);       size[x] += size[u];       mx = std::max(mx, size[u]);     }     mx = std::max(mx, n - size[x]);     if (mx <= n / 2) G = x;   }   void dfs2(int x, int fa) {     size[x] = 1;     for (int i = last[x]; i; i = Next[i])       if (to[i] != fa) dfs2(to[i], x), size[x] += size[to[i]];   }   void dfs3(int x, int fa, int t, int lstdis) {     for (int i = last[x]; i; i = Next[i]) {       int u = to[i];       if (u == fa) continue;       ++cnt;       w[i] = cnt * t - lstdis;       dfs3(u, x, t, lstdis + w[i]);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       add(x, y), add(y, x);     }     dfs(1, 0);     dfs2(G, 0);     siz = 0, cnt = 0;     for (int i = last[G]; i; i = Next[i])       if (siz < n / 3 && siz + size[to[i]] <= 2 * n / 3) {         tag[to[i]] = 1;         siz += size[to[i]];       }     for (int i = last[G]; i; i = Next[i])       if (tag[to[i]]) w[i] = ++cnt, dfs3(to[i], G, 1, cnt);     cnt = 0;     for (int i = last[G]; i; i = Next[i])       if (!tag[to[i]])         ++cnt, w[i] = cnt * (siz + 1), dfs3(to[i], G, siz + 1, cnt * (siz + 1));     for (int i = 1; i <= edge; i += 2)       printf( %d %d %d n , to[i], to[i + 1], w[i] | w[i + 1]);   }   