import sys
sys.setrecursionlimit(10 ** 5)


def dfs(now):
    for nxt, cost in node[now]:
        if visit[nxt] == 0:
            visit[nxt] = visit[now] + cost
            dfs(nxt)


n = int(sys.stdin.readline())
node = [[] for i in range(n + 1)]
for i in range(n):
    list_x = list(map(int, sys.stdin.readline().split()))
    for j in range(1, len(list_x) - 1, 2):
        node[list_x[0]].append([list_x[j], list_x[j + 1]])
visit = [0] * (n + 1)
dfs(1)
visit[1] = 0
tmp = 0
index = 1
for i in range(1, n + 1):
    if tmp < visit[i]:
        tmp = visit[i]
        index = i
visit = [0] * (n + 1)
dfs(index)
visit[index] = 0
print(max(visit))

6efbfe4f8abba83634af309005b53dd18185fe74
<mask token>


def dfs(now):
    for nxt, cost in node[now]:
        if visit[nxt] == 0:
            visit[nxt] = visit[now] + cost
            dfs(nxt)


<mask token>

<mask token>
sys.setrecursionlimit(10 ** 5)


def dfs(now):
    for nxt, cost in node[now]:
        if visit[nxt] == 0:
            visit[nxt] = visit[now] + cost
            dfs(nxt)


<mask token>
for i in range(n):
    list_x = list(map(int, sys.stdin.readline().split()))
    for j in range(1, len(list_x) - 1, 2):
        node[list_x[0]].append([list_x[j], list_x[j + 1]])
<mask token>
dfs(1)
<mask token>
for i in range(1, n + 1):
    if tmp < visit[i]:
        tmp = visit[i]
        index = i
<mask token>
dfs(index)
<mask token>
print(max(visit))

<mask token>
sys.setrecursionlimit(10 ** 5)


def dfs(now):
    for nxt, cost in node[now]:
        if visit[nxt] == 0:
            visit[nxt] = visit[now] + cost
            dfs(nxt)


n = int(sys.stdin.readline())
node = [[] for i in range(n + 1)]
for i in range(n):
    list_x = list(map(int, sys.stdin.readline().split()))
    for j in range(1, len(list_x) - 1, 2):
        node[list_x[0]].append([list_x[j], list_x[j + 1]])
visit = [0] * (n + 1)
dfs(1)
visit[1] = 0
tmp = 0
index = 1
for i in range(1, n + 1):
    if tmp < visit[i]:
        tmp = visit[i]
        index = i
visit = [0] * (n + 1)
dfs(index)
visit[index] = 0
print(max(visit))

import sys
sys.setrecursionlimit(10 ** 5)


def dfs(now):
    for nxt, cost in node[now]:
        if visit[nxt] == 0:
            visit[nxt] = visit[now] + cost
            dfs(nxt)


n = int(sys.stdin.readline())
node = [[] for i in range(n + 1)]
for i in range(n):
    list_x = list(map(int, sys.stdin.readline().split()))
    for j in range(1, len(list_x) - 1, 2):
        node[list_x[0]].append([list_x[j], list_x[j + 1]])
visit = [0] * (n + 1)
dfs(1)
visit[1] = 0
tmp = 0
index = 1
for i in range(1, n + 1):
    if tmp < visit[i]:
        tmp = visit[i]
        index = i
visit = [0] * (n + 1)
dfs(index)
visit[index] = 0
print(max(visit))
