func_code_string: #include <bits/stdc++.h>   using namespace std;   int N;   set<pair<int, int>> E[202020];   signed long long ntot[202020];   int vis[202020];   vector<pair<int, signed long long>> V;   map<pair<int, int>, int> M;   vector<signed long long> chi[202020];   void dfs(int cur, signed long long tot) {     if (vis[cur]) return;     vis[cur] = 1;     V.push_back({cur, tot});     for (auto& e : E[cur]) dfs(e.first, tot + e.second);   }   signed long long X[202020], L[202020];   signed long long Rdia[202020], Rma[202020];   signed long long Ldia[202020], Lma[202020];   signed long long tma;   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N;     for (i = 0; i < (N); i++) {       cin >> x >> y >> r;       E[x - 1].insert({y - 1, r});       E[y - 1].insert({x - 1, r});       M[{x - 1, y - 1}] = M[{y - 1, x - 1}] = r;     }     queue<int> Q;     for (i = 0; i < (N); i++)       if (E[i].size() == 1) Q.push(i);     while (Q.size()) {       int cur = Q.front();       Q.pop();       auto r = *E[cur].begin();       E[cur].clear();       int tar = r.first;       int co = r.second;       E[tar].erase({cur, co});       chi[cur].push_back(0);       chi[cur].push_back(0);       sort((chi[cur].begin()), (chi[cur].end()));       reverse((chi[cur].begin()), (chi[cur].end()));       tma = max(tma, chi[cur][0] + chi[cur][1]);       chi[tar].push_back(chi[cur][0] + co);       ntot[cur] = -1;       if (E[tar].size() == 1) Q.push(tar);     }     for (i = 0; i < (N); i++)       if (ntot[i] >= 0) {         chi[i].push_back(0);         chi[i].push_back(0);         sort((chi[i].begin()), (chi[i].end()));         reverse((chi[i].begin()), (chi[i].end()));         tma = max(tma, chi[i][0] + chi[i][1]);         ntot[i] = chi[i][0];       }     for (i = 0; i < (N); i++)       if (ntot[i] >= 0) {         dfs(i, 0);         break;       }     int C = V.size();     for (i = 0; i < (C); i++) {       X[i] = V[i].second;       L[i] = ntot[V[i].first];     }     signed long long tot = V.back().second + M[{V[0].first, V.back().first}];     signed long long mi = 1LL << 60;     signed long long RR = 0, LL = 1LL << 60;     for (i = C - 1; i >= 0; i--) {       Rma[i] = max(Rma[i + 1], tot - X[i] + L[i]);       Rdia[i] = max({Rdia[i + 1], RR - X[i] + L[i], L[i]});       RR = max(RR, X[i] + L[i]);     }     for (i = 0; i < (C); i++) {       Lma[i] = max(i ? Lma[i - 1] : 0, X[i] + L[i]);       Ldia[i] = max({i ? Ldia[i - 1] : 0, X[i] + L[i] - LL, L[i]});       LL = min(LL, X[i] - L[i]);       if (i == C - 1) {         mi = min(mi, Ldia[i]);       } else {         mi = min(mi, max({Ldia[i], Rdia[i + 1], Lma[i] + Rma[i + 1]}));       }     }     cout << max(tma, mi) << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }   