import sys
from collections import defaultdict
I = sys.stdin.readline
weights=defaultdict(int)
weights2=defaultdict(int)
n = int(I())
if n==1 : print(0);exit(0)
for line in reversed([I() for _ in range(n-1)]):
parent,son,weight=map(int,line.split())
weights2[parent]+=(weight+weights[son])
weights[parent] = max(weights[parent],weight+weights[son])
print(max(weights2.items(),key= lambda x : x[1])[1])
2263번 : 트리 순회문제가 아직 익숙하지 않은 것 같다.
11437번 : LCA,SegmentTree 를 새로 공부해야된다.
골드이상되면 새로운 알고리즘을 공부해야 풀리는 문제들이 많아서 생각보다 시간이 오래 걸리고 있다...