func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename _Tp>   inline _Tp read(_Tp& x) {     char c11 = getchar(), ob = 0;     x = 0;     while (c11 ^  -  && !isdigit(c11)) c11 = getchar();     if (c11 ==  - ) ob = 1, c11 = getchar();     while (isdigit(c11)) x = x * 10 + c11 -  0 , c11 = getchar();     if (ob) x = -x;     return x;   }   const int N = 201000;   const long long inf = 0x3f3f3f3f3f3f3f3f;   struct Edge {     int v, nxt, w;   } a[N << 1];   int head[N], is[N], st[N], vis[N];   long long f[N], pre[N];   long long gl[N], gr[N], hl[N], hr[N], hhl[N], hhr[N], ggl[N], ggr[N];   int n, m, _, top;   long long Ans;   void get_cir(int x, int las) {     if (vis[x]) {       int p = top;       while (st[p] ^ x) --p;       for (register int i = p; i <= top; ++i) is[st[i - p + 1] = st[i]] = 1;       st[0] = -1;       top -= p - 1;       return;     }     vis[st[++top] = x] = 1;     for (int i = head[x]; i && ~st[0]; i = a[i].nxt)       if (a[i].v ^ las) get_cir(a[i].v, x);     if (~st[0]) vis[st[top--]] = 0;   }   void dfs(int x, int las) {     long long sec = 0ll;     for (int i = head[x]; i; i = a[i].nxt)       if (!is[a[i].v] && a[i].v ^ las) {         dfs(a[i].v, x);         f[a[i].v] += a[i].w;         if (f[a[i].v] >= f[x])           sec = f[x], f[x] = f[a[i].v];         else if (f[a[i].v] > sec)           sec = f[a[i].v];       }     Ans = max(Ans, f[x] + sec);   }   inline long long G(int x) { return x ? f[st[x]] - pre[x] : -inf; }   inline long long H(int x) { return x ? f[st[x]] + pre[x] : -inf; }   void work() {     st[0] = st[top];     for (register int x = 1; x <= top; ++x) {       for (register int i = head[st[x - 1]]; i; i = a[i].nxt)         if (a[i].v == st[x]) {           pre[x] = pre[x - 1] + a[i].w;           break;         }       dfs(st[x], 0);     }     for (register int i = 1; i <= top; ++i) {       gl[i] = gl[i - 1], ggl[i] = ggl[i - 1];       hl[i] = hl[i - 1], hhl[i] = hhl[i - 1];       if (G(i) > G(gl[i]))         ggl[i] = gl[i], gl[i] = i;       else if (G(i) > G(ggl[i]))         ggl[i] = i;       if (H(i) > H(hl[i]))         hhl[i] = hl[i], hl[i] = i;       else if (H(i) > H(hhl[i]))         hhl[i] = i;     }     for (register int i = top; i; --i) {       gr[i] = gr[i + 1], ggr[i] = ggr[i + 1];       hr[i] = hr[i + 1], hhr[i] = hhr[i + 1];       if (G(i) > G(gr[i]))         ggr[i] = gr[i], gr[i] = i;       else if (G(i) > G(ggr[i]))         ggr[i] = i;       if (H(i) > H(hr[i]))         hhr[i] = hr[i], hr[i] = i;       else if (H(i) > H(hhr[i]))         hhr[i] = i;     }     long long ans;     if (hl[top] != gl[top])       ans = G(gl[top]) + H(hl[top]);     else       ans = max(G(ggl[top]) + H(hl[top]), G(gl[top]) + H(hhl[top]));     for (register int i = 1; i < top; ++i) {       long long val = pre[top] + H(hl[i]) + G(gr[i + 1]);       long long tmp;       if (gl[i] ^ hl[i])         tmp = G(gl[i]) + H(hl[i]);       else         tmp = max(G(ggl[i]) + H(hl[i]), G(gl[i]) + H(hhl[i]));       val = max(val, tmp);       ++i;       if (gr[i] ^ hr[i])         tmp = G(gr[i]) + H(hr[i]);       else         tmp = max(G(ggr[i]) + H(hr[i]), G(gr[i]) + H(hhr[i]));       val = max(val, tmp);       --i;       ans = min(ans, val);     }     cout << max(ans, Ans) << endl;   }   void init();   void work();   int main() {     init();     work();     return 0;   }   void init() {     read(n);     int u, v, w;     for (register int i = 1; i <= n; ++i) {       read(u), read(v), read(w);       a[++_].v = v, a[_].w = w, a[_].nxt = head[u], head[u] = _;       a[++_].v = u, a[_].w = w, a[_].nxt = head[v], head[v] = _;     }     get_cir(1, 1);   }   