링크 : https://www.acmicpc.net/problem/1167
/*
문제 : 트리의 지름
링크 : https://www.acmicpc.net/problem/1167
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<pair<int, int>> v[100001];
bool visited[100001];
int maxDis, maxNode;
void dfs(int node, int dis){
if(visited[node]) return;
if(maxDis < dis){
maxDis = dis;
maxNode = node;
}
visited[node] = true;
for(int i = 0; i < v[node].size(); i++){
int a = v[node][i].first;
int b = v[node][i].second;
dfs(a, b + dis);
}
}
int main(){
int n;
cin >> n;
int from, to, dis;
for(int i = 0; i < n; i++){
cin >> from;
while(true){
cin >> to;
if(to == -1) break;
cin >> dis;
v[from].push_back({to, dis});
v[to].push_back({from,dis});
}
}
dfs(1,0);
for(int i = 0; i <= n; i++){
visited[i] = false;
}
dfs(maxNode, 0);
cout << maxDis;
return 0;
}