import sys

readline = sys.stdin.readline

from collections import deque

from math import isinf

INF = float("inf")

sys.setrecursionlimit(200000)

n = int(readline())

G = [[] for _ in range(n)]

D = [INF] * n

for _ in [0] * (n - 1):

    s, t, w = list(map(int, readline().split()))

    G[s].append([t, w])

    G[t].append([s, w])

def bfs(s, D):

    dq = deque([s])

    D = [INF] * n

    D[s] = 0

    while dq:

        u = dq.popleft()

        for i in range(len(G[u])):

            e = G[u][i]

            if isinf(D[e[0]]):

                D[e[0]] = D[u] + e[1]

                dq.append(e[0])

    return D

D = bfs(0, D)

maxv = 0

tgt = 0

for i in range(n):

    if isinf(D[i]): continue

    if maxv < D[i]:

        maxv = D[i]

        tgt = i

D = bfs(tgt, D)

print((max(D[i] for i in range(n) if not isinf(D[i]))))
import sys

readline = sys.stdin.readline

def dfs(root):

    visited = [False] * n

    queue = [(0, root)]

    longest = (-1, -1)

    while queue:

        total_weight, node = queue.pop()

        if visited[node]:

            continue

        visited[node] = True

        longest = max(longest, (total_weight, node))

        for w, t in edges[node]:

            if not visited[t]:

                queue.append((total_weight + w, t))

    return longest

n = int(readline())

edges = [set() for _ in range(n)]

for _ in range(n - 1):

    s, t, w = list(map(int, readline().split()))

    edges[s].add((w, t))

    edges[t].add((w, s))

_, ln = dfs(0)

ld, _ = dfs(ln)

print(ld)
import sys

readline = sys.stdin.readline
from collections import deque
from math import isinf

INF = float("inf")
sys.setrecursionlimit(200000)
n = int(readline())
G = [[] for _ in range(n)]
D = [INF] * n
for _ in [0] * (n - 1):
    s, t, w = list(map(int, readline().split()))
    G[s].append([t, w])
    G[t].append([s, w])


def bfs(s, D):
    dq = deque([s])
    D = [INF] * n
    D[s] = 0
    while dq:
        u = dq.popleft()
        for i in range(len(G[u])):
            e = G[u][i]
            if isinf(D[e[0]]):
                D[e[0]] = D[u] + e[1]
                dq.append(e[0])
    return D


D = bfs(0, D)
maxv = 0
tgt = 0
for i in range(n):
    if isinf(D[i]):
        continue
    if maxv < D[i]:
        maxv = D[i]
        tgt = i
D = bfs(tgt, D)
print((max(D[i] for i in range(n) if not isinf(D[i]))))

import sys

readline = sys.stdin.readline


def dfs(root):
    visited = [False] * n
    queue = [(0, root)]
    longest = (-1, -1)
    while queue:
        total_weight, node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        longest = max(longest, (total_weight, node))
        for w, t in edges[node]:
            if not visited[t]:
                queue.append((total_weight + w, t))
    return longest


n = int(readline())
edges = [set() for _ in range(n)]
for _ in range(n - 1):
    s, t, w = list(map(int, readline().split()))
    edges[s].add((w, t))
    edges[t].add((w, s))
_, ln = dfs(0)
ld, _ = dfs(ln)
print(ld)

-from collections import deque -from math import isinf - -INF = float("inf") -sys.setrecursionlimit(200000) -n = int(readline()) -G = [[] for _ in range(n)] -D = [INF] * n -for _ in [0] * (n - 1): -    s, t, w = list(map(int, readline().split())) -    G[s].append([t, w]) -    G[t].append([s, w]) -def bfs(s, D): -    dq = deque([s]) -    D = [INF] * n -    D[s] = 0 -    while dq: -        u = dq.popleft() -        for i in range(len(G[u])): -            e = G[u][i] -            if isinf(D[e[0]]): -                D[e[0]] = D[u] + e[1] -                dq.append(e[0]) -    return D +def dfs(root): +    visited = [False] * n +    queue = [(0, root)] +    longest = (-1, -1) +    while queue: +        total_weight, node = queue.pop() +        if visited[node]: +            continue +        visited[node] = True +        longest = max(longest, (total_weight, node)) +        for w, t in edges[node]: +            if not visited[t]: +                queue.append((total_weight + w, t)) +    return longest -D = bfs(0, D) -maxv = 0 -tgt = 0 -for i in range(n): -    if isinf(D[i]): -        continue -    if maxv < D[i]: -        maxv = D[i] -        tgt = i -D = bfs(tgt, D) -print((max(D[i] for i in range(n) if not isinf(D[i])))) +n = int(readline()) +edges = [set() for _ in range(n)] +for _ in range(n - 1): +    s, t, w = list(map(int, readline().split())) +    edges[s].add((w, t)) +    edges[t].add((w, s)) +_, ln = dfs(0) +ld, _ = dfs(ln) +print(ld)