結果

問題 No.1344 Typical Shortest Path Sum
ユーザー 👑 箱星箱星
提出日時 2021-01-16 14:32:46
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 1,311 bytes
コンパイル時間 12,955 ms
コンパイル使用メモリ 450,152 KB
実行使用メモリ 52,088 KB
最終ジャッジ日時 2024-05-05 16:59:32
合計ジャッジ時間 37,162 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 276 ms
49,824 KB
testcase_01 AC 273 ms
49,972 KB
testcase_02 AC 259 ms
49,904 KB
testcase_03 AC 258 ms
49,940 KB
testcase_04 AC 276 ms
49,944 KB
testcase_05 AC 252 ms
50,016 KB
testcase_06 AC 252 ms
49,672 KB
testcase_07 AC 261 ms
49,768 KB
testcase_08 AC 258 ms
49,712 KB
testcase_09 AC 266 ms
50,008 KB
testcase_10 AC 260 ms
49,916 KB
testcase_11 AC 264 ms
50,004 KB
testcase_12 AC 263 ms
49,940 KB
testcase_13 AC 259 ms
49,880 KB
testcase_14 AC 257 ms
49,916 KB
testcase_15 AC 262 ms
49,856 KB
testcase_16 AC 280 ms
50,348 KB
testcase_17 AC 253 ms
49,712 KB
testcase_18 AC 266 ms
49,668 KB
testcase_19 AC 257 ms
49,976 KB
testcase_20 AC 258 ms
49,708 KB
testcase_21 AC 249 ms
49,908 KB
testcase_22 AC 268 ms
49,932 KB
testcase_23 AC 268 ms
49,792 KB
testcase_24 AC 258 ms
49,776 KB
testcase_25 AC 268 ms
49,696 KB
testcase_26 AC 279 ms
49,732 KB
testcase_27 AC 260 ms
49,936 KB
testcase_28 AC 268 ms
49,904 KB
testcase_29 AC 264 ms
49,864 KB
testcase_30 AC 263 ms
50,076 KB
testcase_31 AC 261 ms
50,024 KB
testcase_32 AC 273 ms
49,752 KB
testcase_33 AC 288 ms
49,876 KB
testcase_34 AC 262 ms
49,948 KB
testcase_35 AC 259 ms
50,072 KB
testcase_36 AC 264 ms
49,824 KB
testcase_37 AC 261 ms
49,676 KB
testcase_38 AC 259 ms
50,052 KB
testcase_39 AC 266 ms
49,924 KB
testcase_40 AC 296 ms
50,620 KB
testcase_41 AC 304 ms
50,512 KB
testcase_42 AC 300 ms
50,720 KB
testcase_43 AC 307 ms
50,540 KB
testcase_44 AC 296 ms
50,340 KB
testcase_45 AC 298 ms
50,560 KB
testcase_46 AC 317 ms
50,612 KB
testcase_47 AC 288 ms
50,580 KB
testcase_48 AC 292 ms
50,428 KB
testcase_49 AC 314 ms
50,500 KB
testcase_50 AC 295 ms
50,612 KB
testcase_51 AC 291 ms
50,668 KB
testcase_52 AC 291 ms
50,624 KB
testcase_53 AC 291 ms
50,768 KB
testcase_54 AC 285 ms
50,728 KB
testcase_55 AC 303 ms
50,660 KB
testcase_56 AC 285 ms
50,384 KB
testcase_57 AC 300 ms
50,556 KB
testcase_58 AC 313 ms
50,680 KB
testcase_59 AC 290 ms
50,612 KB
testcase_60 AC 270 ms
50,052 KB
testcase_61 AC 256 ms
49,980 KB
testcase_62 AC 318 ms
51,804 KB
testcase_63 AC 284 ms
50,284 KB
testcase_64 AC 279 ms
50,420 KB
testcase_65 AC 323 ms
52,088 KB
testcase_66 AC 313 ms
51,884 KB
testcase_67 AC 310 ms
51,792 KB
testcase_68 AC 281 ms
50,132 KB
testcase_69 AC 274 ms
50,316 KB
testcase_70 AC 256 ms
49,860 KB
testcase_71 AC 257 ms
50,044 KB
testcase_72 AC 261 ms
49,776 KB
testcase_73 AC 264 ms
50,084 KB
testcase_74 AC 269 ms
49,672 KB
testcase_75 AC 261 ms
50,064 KB
testcase_76 AC 268 ms
50,032 KB
testcase_77 AC 262 ms
49,920 KB
testcase_78 AC 259 ms
49,792 KB
testcase_79 AC 268 ms
49,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val m = nextInt()
    val INF = 1000000000000000000
    val dist = Array(n) { Array(n) { INF } }
    for (i in 0 until m) {
        val s = nextInt() - 1
        val t = nextInt() - 1
        val d = nextLong()
        dist[s][t] = min(dist[s][t], d)
    }
    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                if (dist[i][k] != INF && dist[k][j] != INF) {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
                }
            }
        }
    }
    for (i in 0 until n) {
        var sum = 0L
        for (j in 0 until n) {
            sum += if (i == j || dist[i][j] == INF) 0 else dist[i][j]
        }
        println(sum)
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve()
    writer.flush()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()!!
fun nextDouble() = next().toDouble()
// endregion
0