https://www.acmicpc.net/problem/11725
import java.util.*;
var arr=Array<ArrayList<Int>>(100001) {ArrayList<Int>()}
var num=Array(0, {0})
var check=Array(0, {false})
var n: Int=0
var bf: Int=0
fun dfs(a:Int){
check[a]=true
num[a]=bf
for(i in arr[a]){
if(check[i]==false){
bf=a
dfs(i)
}
}
}
fun main(args: Array<String>) {
val s=Scanner(System.`in`)
n=s.nextInt()
num=Array(n+1, {0});
check=Array(n+1, {false});
for(i in 0 until n-1){
var u=s.nextInt()
var v=s.nextInt()
arr[u].add(v)
arr[v].add(u)
}
bf=1
dfs(1)
for(i in 2..n){
println(num[i])
}
}