fun main(args: Array) { val (n, k) = readLine()!!.split(" ").map(String::toInt) var a = Array(n, { 0 }) var b = Array(n, { 0 }) var g = Array>(n, { mutableListOf() }) for (i in 0 until n - 1) { val (x, y) = readLine()!!.split(" ").map(String::toInt) a[i] = x - 1 b[i] = y - 1 g[a[i]].add(i) g[b[i]].add(i) } if (n < k) { println(-1) return } var dist = Array(n, { if (it == 0) { 0L } else { -1L }}) fun solve(now: Int, depth: Long) { dist[now] = depth for (id in g[now]) { val to = a[id] xor b[id] xor now if (dist[to] != -1L) continue solve(to, depth + 1) } } solve(0, 0) dist.sort() var ans: Long = 0 for (i in 0 until k) ans += dist[i] println(ans) }