func_code_string: #include <bits/stdc++.h>   using namespace std;   long long last = -1;   void dfs(long long s, vector<vector<pair<long long, long long>>> grf,            vector<long long> &vis, long long &cost) {     vis[s] = 1;     last = s;     for (auto x : grf[s]) {       long long v = x.first, d = x.second;       if (vis[v] == 0) {         cost += d;         dfs(v, grf, vis, cost);       }     }   }   signed main() {     long long n;     cin >> n;     vector<vector<pair<long long, long long>>> grf(n + 1);     long long sum = 0;     for (long long i = 0; i < n; i++) {       long long u, v, w;       cin >> u >> v >> w;       grf[u].push_back({v, w});       grf[v].push_back({u, 0});       sum += w;     }     long long cost = 0;     vector<long long> vis(n + 1, 0);     dfs(1, grf, vis, cost);     if (last != 1) {       for (auto x : grf[last]) {         if (x.first == 1) cost += x.second;       }     }     cout << min(cost, sum - cost);     return 0;   }   