import java.io.*;
import java.util.HashMap;
import java.util.Map;
class Main{
static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
static int N = 10010;
static int ans = 0;
static Map<Integer, Map<Integer, Integer>> graph = new HashMap(N);
public static void add(int a, int b, int c){
graph.putIfAbsent(a, new HashMap());
graph.get(a).put(b, c);
}
public static void main(String[] args) throws Exception{
int n = Integer.valueOf(read.readLine());
for(int i = 1; i < n; i++){
String[] ss = read.readLine().split(" ");
int a = Integer.valueOf(ss[0]);
int b = Integer.valueOf(ss[1]);
int c = Integer.valueOf(ss[2]);
add(a, b, c); add(b, a, c);
}
dfs(1, -1);
System.out.println(ans);
}
public static int dfs(int root, int father){
int p1 = 0, p2 = 0;
for(Integer j: graph.get(root).keySet()){
//如果是父节点, 则不走
if(j == father) continue;
int cld = dfs(j, root) + graph.get(root).get(j);
if(cld >= p1){
p2 = p1; p1 = cld;
}else if(cld > p2) p2 = cld;
}
ans = Math.max(ans, p1 + p2);
return p1;
}
}