from heapq import heappop, heappush



INF = 10 ** 20



n = int(eval(input()))

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

for _ in range(n - 1):

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

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

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



cost = [INF] * n

que = [(0, 0)]

cost[0] = 0



while que:

  acc, num = heappop(que)

  for weight, to in edges[num]:

    if weight + acc < cost[to]:

      cost[to] = weight + acc

      heappush(que, (weight + acc, to))



max_ind = cost.index(max(cost))

cost = [INF] * n

que = [(0, max_ind)]

cost[max_ind] = 0

while que:

  acc, num = heappop(que)

  for weight, to in edges[num]:

    if weight + acc < cost[to]:

      cost[to] = weight + acc

      heappush(que, (weight + acc, to))



print((max(cost)))

from heapq import heappop, heappush



INF = 10 ** 20



def main():

  n = int(eval(input()))

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

  for _ in range(n - 1):

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

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

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

  

  def func(start):

    cost = [INF] * n

    que = [(0, start)]

    cost[start] = 0

    

    while que:

      acc, num = heappop(que)

      for weight, to in edges[num]:

        if weight + acc < cost[to]:

          cost[to] = weight + acc

          heappush(que, (weight + acc, to))

    return cost

  

  cost1 = func(0)

  max_ind = cost1.index(max(cost1))

  cost2 = func(max_ind)

  

  print((max(cost2)))

main()

from heapq import heappop, heappush

INF = 10**20
n = int(eval(input()))
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    s, t, w = list(map(int, input().split()))
    edges[s].append((w, t))
    edges[t].append((w, s))
cost = [INF] * n
que = [(0, 0)]
cost[0] = 0
while que:
    acc, num = heappop(que)
    for weight, to in edges[num]:
        if weight + acc < cost[to]:
            cost[to] = weight + acc
            heappush(que, (weight + acc, to))
max_ind = cost.index(max(cost))
cost = [INF] * n
que = [(0, max_ind)]
cost[max_ind] = 0
while que:
    acc, num = heappop(que)
    for weight, to in edges[num]:
        if weight + acc < cost[to]:
            cost[to] = weight + acc
            heappush(que, (weight + acc, to))
print((max(cost)))

from heapq import heappop, heappush

INF = 10**20


def main():
    n = int(eval(input()))
    edges = [[] for _ in range(n)]
    for _ in range(n - 1):
        s, t, w = list(map(int, input().split()))
        edges[s].append((w, t))
        edges[t].append((w, s))

    def func(start):
        cost = [INF] * n
        que = [(0, start)]
        cost[start] = 0
        while que:
            acc, num = heappop(que)
            for weight, to in edges[num]:
                if weight + acc < cost[to]:
                    cost[to] = weight + acc
                    heappush(que, (weight + acc, to))
        return cost

    cost1 = func(0)
    max_ind = cost1.index(max(cost1))
    cost2 = func(max_ind)
    print((max(cost2)))


main()

-n = int(eval(input())) -edges = [[] for _ in range(n)] -for _ in range(n - 1): -    s, t, w = list(map(int, input().split())) -    edges[s].append((w, t)) -    edges[t].append((w, s)) -cost = [INF] * n -que = [(0, 0)] -cost[0] = 0 -while que: -    acc, num = heappop(que) -    for weight, to in edges[num]: -        if weight + acc < cost[to]: -            cost[to] = weight + acc -            heappush(que, (weight + acc, to)) -max_ind = cost.index(max(cost)) -cost = [INF] * n -que = [(0, max_ind)] -cost[max_ind] = 0 -while que: -    acc, num = heappop(que) -    for weight, to in edges[num]: -        if weight + acc < cost[to]: -            cost[to] = weight + acc -            heappush(que, (weight + acc, to)) -print((max(cost))) + + +def main(): +    n = int(eval(input())) +    edges = [[] for _ in range(n)] +    for _ in range(n - 1): +        s, t, w = list(map(int, input().split())) +        edges[s].append((w, t)) +        edges[t].append((w, s)) + +    def func(start): +        cost = [INF] * n +        que = [(0, start)] +        cost[start] = 0 +        while que: +            acc, num = heappop(que) +            for weight, to in edges[num]: +                if weight + acc < cost[to]: +                    cost[to] = weight + acc +                    heappush(que, (weight + acc, to)) +        return cost + +    cost1 = func(0) +    max_ind = cost1.index(max(cost1)) +    cost2 = func(max_ind) +    print((max(cost2))) + + +main()