結果
問題 | No.1344 Typical Shortest Path Sum |
ユーザー |
|
提出日時 | 2021-01-16 14:32:46 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 348 ms / 2,000 ms |
コード長 | 1,311 bytes |
コンパイル時間 | 17,256 ms |
コンパイル使用メモリ | 441,176 KB |
実行使用メモリ | 55,052 KB |
最終ジャッジ日時 | 2024-11-27 16:19:51 |
合計ジャッジ時間 | 40,983 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 77 |
ソースコード
import java.io.PrintWriterimport java.util.*import kotlin.math.*fun PrintWriter.solve() {val n = nextInt()val m = nextInt()val INF = 1000000000000000000val dist = Array(n) { Array(n) { INF } }for (i in 0 until m) {val s = nextInt() - 1val t = nextInt() - 1val 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 = 0Lfor (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 Scannerprivate 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