from collections import defaultdict, deque # bfs to bfs で最長距離を求める n = int(input()) graph = defaultdict(list) for _ in range(n - 1): u, v, w = map(int, input().split()) graph[u].append((v, w)) graph[v].append((u, w)) def bfs(start): dist = [-1] * (n + 1) dist[start] = 0 queue = deque([start]) while queue: node = queue.popleft() for neighbor, weight in graph[node]: if dist[neighbor] == -1: dist[neighbor] = dist[node] + weight queue.append(neighbor) farthest_node = dist.index(max(dist)) return farthest_node, dist[farthest_node] u, _ = bfs(1) _, diameter = bfs(u) print(diameter)