N = int(input()) G = [[] for _ in range(N)] for _ in range(N - 1): u, v, w = map(int, input().split()) u -= 1 v -= 1 G[u].append((v, w)) G[v].append((u, w)) done = [0] * N Q = [~0, 0] # 根をスタックに追加 dp = ["?"] * N ET = [] ans = 0 while Q: i = Q.pop() if i >= 0: # 行きがけの処理 done[i] = 1 # ET.append(i) for (a, w) in G[i]: if done[a]: continue Q.append(~a) # 帰りがけの処理をスタックに追加 Q.append(a) # 行きがけの処理をスタックに追加 else: # 帰りがけの処理 i = ~i L = [] for (x, w) in G[i]: if(dp[x] != "?"): L.append(dp[x] + w) L.sort(reverse=True) # print(i, L) if(len(L) >= 1): dp[i] = max(0, L[0]) ans = max(ans, L[0]) else: dp[i] = 0 if(len(L) >= 2): ans = max(ans, sum(L[:2])) print(ans)