# 트리의 지름 - BOJ

트리의 지름 - BOJ

def dfs(v):
    visit = [0 for _ in range(10001)]
    s = [[v, 0]]
    visit[v] = 1
    max_dist, v_num = 0, 1
    while s:
        x = s.pop()
        if max_dist < x[1]:
            max_dist = x[1]
            v_num = x[0]
        for i in range(len(dist[x[0]])):
            nx, weight = dist[x[0]][i]
            if not visit[nx]:
                visit[nx] = 1
                s.append([nx, x[1] + weight])
    return [v_num, max_dist]

n = int(input())
dist = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b, w = map(int, input().split())
    dist[a].append([b, w])
    dist[b].append([a, w])

farthest = dfs(1)[0]
print(dfs(farthest)[1])