https://www.acmicpc.net/problem/1260
import java.util.*;
var edge=Array(0, {Array(0, {0})})
var check=Array(0, {false})
var n: Int=0
var m: Int=0
var v: Int=0
fun dfs(v:Int){
check[v]=true;
print("${v} ")
for(i in 1..n){
if(edge[v][i]==1 && check[i]==false) dfs(i)
}
}
fun bfs(s:Int){
var q=LinkedList<Int>()
q.add(s)
check[s]=true
while(q.isEmpty()==false){
val v=q.peek()
q.poll()
print("${v} ")
for(i in 1..n){
if(edge[v][i]==1 && check[i]==false){
q.add(i)
check[i]=true
}
}
}
}
fun main(args: Array<String>) {
val s=Scanner(System.`in`)
n=s.nextInt()
m=s.nextInt()
v=s.nextInt()
edge=Array(n+1, {Array(n+1, {0})})
check=Array(n+1, {false});
while(m-->0){
var f=s.nextInt()
var t=s.nextInt()
edge[f][t]=1
edge[t][f]=1
}
dfs(v)
check=Array(n+1, {false});
println()
bfs(v)
}