원본 문제 : https://www.acmicpc.net/problem/2606
문제 참고 : https://youjourney.tistory.com/132
<첫번째>
import java.io.*
import java.util.*
var computerCount = 0
var graph: Array<IntArray> = arrayOf()
val INF: Int = 100000
fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
computerCount = readLine().toInt()
graph = Array( computerCount + 1 ) { IntArray( computerCount + 1) }
var conn = readLine().toInt()
for ( i in 1..computerCount ) {
for ( j in 1..computerCount ) {
if (i==j) continue
graph[i][j] = INF
}
}
while ( conn-- > 0 ) {
val str = readLine().split(" ")
val start = str[0].toInt()
val end = str[1].toInt()
graph[start][end] = Math.min(graph[start][end], 1)
graph[end][start] = Math.min(graph[end][start], 1)
}
floydWarshall()
}
fun floydWarshall() {
var count = 0
for ( k in 1..computerCount ) {
for ( i in 1..computerCount ) {
for ( j in 1..computerCount ) {
graph[i][j] = Math.min(graph[i][k] + graph[k][j], graph[i][j])
}
}
}
for ( i in 1..computerCount ) {
if ( graph[1][i] >= INF ) graph[1][i] = 0
if ( graph[1][i] > 0 ) count += 1
}
println(count)
}
'코딩연습' 카테고리의 다른 글
[백준] 케빈 베이컨 (1389)(Kotlin) (0) | 2020.02.03 |
---|---|
[백준] 경로 찾기 (11403)(Kotlin) (0) | 2020.01.30 |
[백준] 플로이드 (11404)(Kotlin) (0) | 2020.01.30 |
[백준] 숨바꼭질 (1697)(Kotlin) (0) | 2020.01.29 |
[백준] 토마토 (7576)(Kotlin) (0) | 2020.01.29 |
댓글