結果
問題 | No.807 umg tours |
ユーザー | dot_haraai |
提出日時 | 2021-06-07 23:13:20 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 414 ms / 4,000 ms |
コード長 | 1,704 bytes |
コンパイル時間 | 4,170 ms |
コンパイル使用メモリ | 87,376 KB |
実行使用メモリ | 36,904 KB |
最終ジャッジ日時 | 2024-11-25 05:21:54 |
合計ジャッジ時間 | 10,323 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 1 ms
6,816 KB |
testcase_11 | AC | 226 ms
22,560 KB |
testcase_12 | AC | 220 ms
21,528 KB |
testcase_13 | AC | 288 ms
25,192 KB |
testcase_14 | AC | 123 ms
13,440 KB |
testcase_15 | AC | 107 ms
12,288 KB |
testcase_16 | AC | 322 ms
32,108 KB |
testcase_17 | AC | 378 ms
30,024 KB |
testcase_18 | AC | 414 ms
36,904 KB |
testcase_19 | AC | 402 ms
36,476 KB |
testcase_20 | AC | 216 ms
17,664 KB |
testcase_21 | AC | 221 ms
18,176 KB |
testcase_22 | AC | 96 ms
9,728 KB |
testcase_23 | AC | 74 ms
8,448 KB |
testcase_24 | AC | 231 ms
33,872 KB |
testcase_25 | AC | 356 ms
36,624 KB |
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 18) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated] /home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'times' [UnusedImport] /home/judge/data/code/Main.nim(2, 26) Warning: imported and not used: 'strformat' [UnusedImport] /home/judge/data/code/Main.nim(2, 18) Warning: imported and not used: 'future' [UnusedImport] /home/judge/data/code/Main.nim(2, 8) Warning: imported and not used: 'critbits' [UnusedImport] /home/judge/data/code/Main.nim(1, 41) Warning: imported and not used: 'algorithm' [UnusedImport] /home/judge/data/code/Main.nim(1, 52) Warning: imported and not used: 'tables' [UnusedImport] /home/judge/data/code/Main.nim(1, 60) Warning: imported and not used: 'sets' [UnusedImport] /home/judge/data/code/Main.nim(1, 66) Warning: imported and not used: 'lists' [UnusedImport] /home/judge/data/code/Main.nim(1, 73) Warning: imported and not used: 'intsets' [UnusedImport]
ソースコード
import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc solve()= var n = scan() m = scan() es = newseqwith(n,newseq[int]()) cs = newseqwith(n,newseq[int]()) for i in 0..<m: var (a,b,c) = (scan()-1,scan()-1,scan()) es[a].add(b) es[b].add(a) cs[a].add(c) cs[b].add(c) # 無視した最大重みの辺を保持してbfsは? var cost = newseqwith(n,newseqwith(2,int.high.div(4))) proc bfs(s:int)= # (コスト、頂点、チケット使用フラグ) var q = initDeque[(int,int,int)]() cost[s][0]=0 cost[s][1]=0 q.addLast((0,s,0)) q.addLast((0,s,1)) while q.len>0: var (cst,v,ticket) = q.popFirst() if cost[v][ticket]<cst:continue for nIdx in 0..<es[v].len: var nxt = es[v][nIdx] c = cs[v][nIdx] if cost[nxt][0] > cost[v][0]+c: cost[nxt][0] = cost[v][0]+c q.addLast((cost[nxt][0],nxt,0)) if cost[nxt][1] > min(cost[v][0],cost[v][1]+c): cost[nxt][1] = min(cost[v][0],cost[v][1]+c) q.addLast((cost[nxt][1],nxt,1)) bfs(0) #echo cost.join("\n") for i in 0..<n: echo cost[i][0]+cost[i][1] solve()