func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   struct Data {     int u, v, w;     Data() {}     Data(int x, int y, int z) : u(x), v(y), w(z) {}   };   int n;   vector<Data> edge, ans;   vector<int> neighbor[N];   void dfs(int u, int par, vector<int> &leaf) {     if (neighbor[u].size() == 1) {       leaf.push_back(u);       return;     }     for (auto v : neighbor[u])       if (v != par) dfs(v, u, leaf);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int x, y, w;       cin >> x >> y >> w;       edge.push_back(Data(x, y, w));       neighbor[x].push_back(y);       neighbor[y].push_back(x);     }     for (int i = 1; i <= n; i++)       if (neighbor[i].size() == 2) return cout <<  NO , 0;     cout <<  YES n ;     for (auto Q : edge) {       int u = Q.u, v = Q.v, w = Q.w;       vector<int> Uleaf, Vleaf;       dfs(u, v, Uleaf);       dfs(v, u, Vleaf);       int u1 = Uleaf.front(), u2 = Uleaf.back();       int v1 = Vleaf.front(), v2 = Vleaf.back();       ans.push_back(Data(u1, v1, w / 2));       ans.push_back(Data(u2, v2, w / 2));       if (u1 != u2) ans.push_back(Data(u1, u2, -w / 2));       if (v1 != v2) ans.push_back(Data(v1, v2, -w / 2));     }     cout << ans.size() <<   n ;     for (auto Q : ans) {       int u = Q.u, v = Q.v, w = Q.w;       cout << u <<     << v <<     << w <<   n ;     }   }   