import sys sys.setrecursionlimit(1 << 25) N = int(input()) from collections import defaultdict tree = defaultdict(list) for _ in range(N - 1): u, v, w = map(int, input().split()) tree[u].append((v, w)) tree[v].append((u, w)) max_path = 0 def dfs(node, parent): global max_path best1, best2 = 0, 0 for neighbor, weight in tree[node]: if neighbor == parent: continue gain = dfs(neighbor, node) + weight gain = max(0, gain) if gain > best1: best1, best2 = gain, best1 elif gain > best2: best2 = gain max_path = max(max_path, best1 + best2) return best1 dfs(1, -1) print(max_path)