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)) def dfs(node, parent, dist): farthest = (dist, node) for neighbor, weight in tree[node]: if neighbor != parent: candidate = dfs(neighbor, node, dist + weight) if candidate[0] > farthest[0]: farthest = candidate return farthest _, farthest_node = dfs(1, -1, 0) max_dist, _ = dfs(farthest_node, -1, 0) print(max(0, max_dist))