# Include <cstdlib> # include <iostream> # include <cstdio> # include <cmath> # include <cstring> # include <algorithm> # include <vector> # include <set> # define ll long # define INF 0x7fffffff # define e 1e-9 # define M 100 # define n 10010 using namespace STD; int maxv, Len [N] [N], vis [N]; char STR [100]; vector <int> G [N]; int DFS (int u) {vis [u] = 1; int S = G [u]. size (); int one = 0, twe = 0; For (INT I = 0; I <s; I ++) {int v = G [u] [I]; if (! Vis [v]) {int Dep = Len [u] [v] + DFS (V); If (DEP> one) {twe = one; one = Dep ;} else if (DEP> twe) twe = Dep ;}} int d = one + twe; If (maxv <D) maxv = D; return one ;}int main () {# ifndef online_judge freopen ("ex. in "," r ", stdin); # endif while (gets (STR )! = NULL) {maxv = 0; int maxn = 0; memset (Len, 0, sizeof (LEN); memset (VIS, 0, sizeof (VIS); int l, u, V; while (strlen (STR)> 0) // The input may be disturbing !! Speechless {sscanf (STR, "% d", & U, & V, & L); If (u> maxn) maxn = u; if (V> maxn) maxn = V; G [u]. push_back (V); G [v]. push_back (U); Len [u] [v] = L; Len [v] [u] = L; If (gets (STR) = NULL) break ;} DFS (U); cout <maxv <Endl; For (INT I = 1; I <= maxn; I ++) // optimized !! G [I]. Clear ();} return 0 ;}