def root(d, x) d[x] < 0 ? x : root(d,d[x]) end n = read_line.to_i d = [-1] * n ans = "" (2..n).each { a,b,c = read_line.split a,b = root(d,a.to_i-1), root(d,b.to_i-1) next if a == b a,b = b,a if d[a]>d[b] d[a],d[b],ans = d[a]+d[b],a,c } puts ans