結果

問題 No.1344 Typical Shortest Path Sum
ユーザー 👑 箱
提出日時 2021-01-16 14:32:46
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 1,311 bytes
コンパイル時間 15,448 ms
コンパイル使用メモリ 427,108 KB
実行使用メモリ 52,956 KB
最終ジャッジ日時 2023-08-18 11:39:06
合計ジャッジ時間 40,526 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 266 ms
50,368 KB
testcase_01 AC 264 ms
50,468 KB
testcase_02 AC 270 ms
50,740 KB
testcase_03 AC 269 ms
50,412 KB
testcase_04 AC 267 ms
50,548 KB
testcase_05 AC 262 ms
50,452 KB
testcase_06 AC 264 ms
50,352 KB
testcase_07 AC 263 ms
50,408 KB
testcase_08 AC 260 ms
50,336 KB
testcase_09 AC 266 ms
50,396 KB
testcase_10 AC 267 ms
50,336 KB
testcase_11 AC 267 ms
50,280 KB
testcase_12 AC 265 ms
50,340 KB
testcase_13 AC 269 ms
50,176 KB
testcase_14 AC 269 ms
50,300 KB
testcase_15 AC 271 ms
50,504 KB
testcase_16 AC 293 ms
50,664 KB
testcase_17 AC 274 ms
50,568 KB
testcase_18 AC 274 ms
50,372 KB
testcase_19 AC 276 ms
50,304 KB
testcase_20 AC 272 ms
50,176 KB
testcase_21 AC 274 ms
50,256 KB
testcase_22 AC 274 ms
50,540 KB
testcase_23 AC 274 ms
50,340 KB
testcase_24 AC 272 ms
50,564 KB
testcase_25 AC 272 ms
50,288 KB
testcase_26 AC 271 ms
50,284 KB
testcase_27 AC 266 ms
50,372 KB
testcase_28 AC 267 ms
50,292 KB
testcase_29 AC 268 ms
50,316 KB
testcase_30 AC 272 ms
50,740 KB
testcase_31 AC 265 ms
50,304 KB
testcase_32 AC 261 ms
50,400 KB
testcase_33 AC 263 ms
50,280 KB
testcase_34 AC 267 ms
50,304 KB
testcase_35 AC 267 ms
50,636 KB
testcase_36 AC 267 ms
50,400 KB
testcase_37 AC 269 ms
50,588 KB
testcase_38 AC 263 ms
50,364 KB
testcase_39 AC 264 ms
50,456 KB
testcase_40 AC 294 ms
52,956 KB
testcase_41 AC 295 ms
52,628 KB
testcase_42 AC 296 ms
52,560 KB
testcase_43 AC 309 ms
52,680 KB
testcase_44 AC 298 ms
52,576 KB
testcase_45 AC 297 ms
52,596 KB
testcase_46 AC 306 ms
52,888 KB
testcase_47 AC 290 ms
52,596 KB
testcase_48 AC 295 ms
52,688 KB
testcase_49 AC 302 ms
52,648 KB
testcase_50 AC 301 ms
52,628 KB
testcase_51 AC 291 ms
52,612 KB
testcase_52 AC 297 ms
52,672 KB
testcase_53 AC 302 ms
52,552 KB
testcase_54 AC 296 ms
52,668 KB
testcase_55 AC 298 ms
52,808 KB
testcase_56 AC 300 ms
52,500 KB
testcase_57 AC 301 ms
52,540 KB
testcase_58 AC 313 ms
52,628 KB
testcase_59 AC 303 ms
52,772 KB
testcase_60 AC 278 ms
50,604 KB
testcase_61 AC 272 ms
50,492 KB
testcase_62 AC 321 ms
52,696 KB
testcase_63 AC 289 ms
52,784 KB
testcase_64 AC 293 ms
52,836 KB
testcase_65 AC 331 ms
52,696 KB
testcase_66 AC 324 ms
52,704 KB
testcase_67 AC 324 ms
52,768 KB
testcase_68 AC 293 ms
52,504 KB
testcase_69 AC 289 ms
52,444 KB
testcase_70 AC 273 ms
50,556 KB
testcase_71 AC 268 ms
50,284 KB
testcase_72 AC 268 ms
50,288 KB
testcase_73 AC 261 ms
50,312 KB
testcase_74 AC 270 ms
50,528 KB
testcase_75 AC 264 ms
50,304 KB
testcase_76 AC 262 ms
50,404 KB
testcase_77 AC 266 ms
50,284 KB
testcase_78 AC 262 ms
50,468 KB
testcase_79 AC 262 ms
50,356 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