https://www.acmicpc.net/problem/11724
import java.util.*;
var arr=Array(0, {Array(0, {0})})
var check=Array(0, {false})
var n: Int=0
fun dfs(a:Int){
check[a]=true
for(i in 1..n){
if(arr[a][i]==1 && check[i]==false) dfs(i)
}
}
fun main(args: Array<String>) {
val s=Scanner(System.`in`)
n=s.nextInt()
var m=s.nextInt()
arr=Array(n+1, {Array(n+1, {0})})
check=Array(n+1, {false});
while(m-->0){
var u=s.nextInt()
var v=s.nextInt()
arr[u][v]=1
arr[v][u]=1
}
var count=0
for(i in 1..n){
if(check[i]==false){
dfs(i)
count++
}
}
print(count)
}