import java.io.PrintWriter import java.util.* fun PrintWriter.solve() { val n = nextInt() val graph = Array(n) { mutableListOf() } while (true) { val a = nextInt() - 1 val b = nextInt() - 1 val c = next() graph[a].add(b) graph[b].add(a) var num = 0 val stack = Stack>() stack.push(0 to -1) while (stack.isNotEmpty()) { val (v, p) = stack.pop() num++ for (w in graph[v]) { if (w != p) { stack.push(w to v) } } } if (num == n) { println(c) return } } } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion