N = int(input()) es = [[] for _ in range(N)] for _ in range(N-1): u, v, w = map(int, input().split()) u, v = u-1, v-1 es[u].append((v, w)) es[v].append((u, w)) mx_cst = mx_idx = 0 stk = [(0, -1, 0)] while stk: c, p, d = stk.pop() if mx_cst < d: mx_cst = d mx_idx = c for t, w in es[c]: if t == p: continue stk.append((t, c, max(0, d+w))) mx_cst1 = mx_idx1 = 0 stk = [(mx_idx, -1, 0)] while stk: c, p, d = stk.pop() if mx_cst1 < d: mx_cst1 = d mx_idx1 = c for t, w in es[c]: if t == p: continue stk.append((t, c, max(0, d+w))) print(mx_cst1)