import java.util.*;
import java.io.*;
class Main{
static boolean[] visited;
static ArrayList<Node>[] nodes;
static int n;
static int max = 0;
static int maxIdx = 0;
public static void main(String args[])throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
String line;
visited = new boolean[n+1];
nodes = new ArrayList[n+1];
for(int i=0 ; i<=n ; i++){
nodes[i] = new ArrayList<>();
}
while((line = br.readLine()) != null){
StringTokenizer st = new StringTokenizer(line);
int parent = Integer.parseInt(st.nextToken());
int child = Integer.parseInt(st.nextToken());
int weight = Integer.parseInt(st.nextToken());
nodes[parent].add(new Node(child,weight));
nodes[child].add(new Node(parent,weight));
}
visited[1]=true;
dfs(1,0);
visited = new boolean[n+1];
visited[maxIdx] = true;
dfs(maxIdx,0);
System.out.println(max);
}
public static void dfs(int idx, int cnt){
//최대 값과 , 그때의 노드 번호 갱신 로직
if(max < cnt){
max = cnt;
maxIdx = idx;
}
for(Node node : nodes[idx]){
if(!visited[node.idx]){
visited[node.idx] = true;
dfs(node.idx , cnt+node.cnt);
}
}
}
}
class Node{
int idx, cnt;
Node(int idx, int cnt){
this.idx = idx;
this.cnt = cnt;
}
}
얻어갈 점: