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)

maxv = 0

for i in range(n):

    if isinf(D[i]): continue

    maxv = max(maxv, D[i])

print(maxv)
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
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)
maxv = 0
for i in range(n):
    if isinf(D[i]):
        continue
    maxv = max(maxv, D[i])
print(maxv)

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]))))

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