import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class Main { static List> list; static long ans; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = n - 1; list = new ArrayList<>(n); for (int i = 0; i < n; i++) { list.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]) - 1; int b = Integer.parseInt(sa[1]) - 1; int c = Integer.parseInt(sa[2]); list.get(a).add(new Hen(b, c)); list.get(b).add(new Hen(a, c)); } br.close(); dfs(0, -1); System.out.println(ans); } static long dfs(int x, int p) { long ret = 0; PriorityQueue que = new PriorityQueue<>(Collections.reverseOrder()); for (Hen h : list.get(x)) { if (h.v != p) { long res = dfs(h.v, x) + h.c; ret = Math.max(ret, res); que.add(res); } } long val = 0; for (int i = 0; i < 2; i++) { if (!que.isEmpty()) { val += que.poll(); } } ans = Math.max(ans, val); return ret; } static class Hen { int v, c; public Hen(int v, int c) { this.v = v; this.c = c; } } }