結果

問題 No.807 umg tours
ユーザー yudedakoyudedako
提出日時 2020-08-27 13:54:31
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 2,357 ms / 4,000 ms
コード長 1,252 bytes
コンパイル時間 17,279 ms
コンパイル使用メモリ 426,140 KB
実行使用メモリ 109,572 KB
最終ジャッジ日時 2023-08-15 12:59:21
合計ジャッジ時間 49,473 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 330 ms
53,264 KB
testcase_01 AC 327 ms
53,252 KB
testcase_02 AC 346 ms
53,476 KB
testcase_03 AC 346 ms
53,312 KB
testcase_04 AC 334 ms
53,248 KB
testcase_05 AC 333 ms
53,260 KB
testcase_06 AC 347 ms
53,316 KB
testcase_07 AC 349 ms
53,428 KB
testcase_08 AC 302 ms
53,024 KB
testcase_09 AC 314 ms
53,156 KB
testcase_10 AC 317 ms
53,044 KB
testcase_11 AC 1,583 ms
80,600 KB
testcase_12 AC 1,553 ms
80,592 KB
testcase_13 AC 1,721 ms
90,472 KB
testcase_14 AC 1,251 ms
73,852 KB
testcase_15 AC 1,132 ms
67,076 KB
testcase_16 AC 1,709 ms
89,592 KB
testcase_17 AC 2,251 ms
106,592 KB
testcase_18 AC 2,259 ms
106,484 KB
testcase_19 AC 1,810 ms
95,824 KB
testcase_20 AC 1,556 ms
77,360 KB
testcase_21 AC 1,588 ms
76,320 KB
testcase_22 AC 1,276 ms
71,996 KB
testcase_23 AC 1,222 ms
73,004 KB
testcase_24 AC 1,755 ms
100,552 KB
testcase_25 AC 2,357 ms
109,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*
import kotlin.collections.ArrayList


data class Road(val to: Int, val length: Int)
fun main() {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val nodes = Array(n){ArrayList<Road>()}
    repeat(m) {
        val (a, b, c) = readLine()!!.trim().split(' ').map(String::toInt)
        nodes[a - 1].add(Road(to = b - 1, length = c))
        nodes[b - 1].add(Road(to = a - 1, length = c))
    }
    val memo = Array(2){ LongArray(n){Long.MAX_VALUE} }
    val priorityQueue = PriorityQueue<Triple<Long, Int, Int>>(compareBy(Triple<Long, *, *>::first))
    memo[0][0] = 0
    memo[1][0] = 0
    priorityQueue.add(Triple(0L, 0, 0))
    while (priorityQueue.isNotEmpty()) {
        val (len, use, pos) = priorityQueue.poll()
        if (memo[use][pos] < len) continue
        for ((next, d) in nodes[pos]) {
            if (memo[use][next] > len + d) {
                memo[use][next] = len + d
                priorityQueue.add(Triple(len + d, use, next))
            }
            if (use == 0 && memo[1][next] > len) {
                memo[1][next] = len
                priorityQueue.add(Triple(len, 1, next))
            }
        }
    }
    for (i in 0 until n){
        println(memo[0][i] + memo[1][i])
    }
}
0