import java.io.*;
import java.util.*;
class Main{
static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
static int N = 10010, INF = 0x3f3f3f3f;
static Map<Integer, Map<Integer, Integer>> graph = new HashMap(N);
static int[] downPath1 = new int[N], downPath2 = new int[N], path1Node = new int[N], path2Node = new int[N], upPath = new int[N];
public static void add(int a, int b, int c){
graph.putIfAbsent( a, new HashMap());
graph.get(a).put(b, c);
}
public static int dfsDown(int node, int father){
if(graph.get(node) == null) return 0;
for(Integer k: graph.get(node).keySet()){
if(k == father) continue;
int p = dfsDown( k, node) + graph.get(node).get(k);
if(p >= downPath1[node]){
downPath2[node] = downPath1[node];
path2Node[node] = path1Node[node];
downPath1[node] = p;
path1Node[node] = k;
}else if(p > downPath2[node]){
downPath2[node] = p;
path2Node[node] = k;
}
}
return downPath1[node];
}
public static void dfsUp(int node, int father){
if(graph.get(node) == null) return;
for(Integer k: graph.get(node).keySet()){
if(k == father) continue;
if(path1Node[node] == k){
upPath[k] = Math.max( upPath[node], downPath2[node] ) + graph.get(node).get(k);
}else{
upPath[k] = Math.max( upPath[node], downPath1[node] ) + graph.get(node).get(k);
}
dfsUp(k, node);
}
}
public static void main(String[] args) throws Exception{
int n = Integer.valueOf(read.readLine().trim());
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);
}
dfsDown(1, -1);
dfsUp(1, -1);
int min = INF;
for(int i = 1; i <= n; i++){
min = Math.min(min, Math.max( downPath1[i], upPath[i]));
}
System.out.println(min);
}
}
nice!