N = gets.to_i cost = Array.new(N) {Array.new(N, Float::INFINITY)} (N*(N-1)/2).times { a, b, c = gets.split(" ").map{|s| s.to_i} cost[a-1][b-1] = cost[b-1][a-1] = c } mincost = Array.new(N, Float::INFINITY) used = Array.new(N, false) mincost[0] = 0 res = 0 loop { v = -1 0.upto(N-1) {|u| v = u if !used[u] and (v == -1 or mincost[u] < mincost[v]) } break if v == -1 used[v] = true res = mincost[v] if res < mincost[v] 0.upto(N-1) {|u| mincost[u] = cost[v][u] if mincost[u] > cost[v][u] } } puts res