結果

問題 No.807 umg tours
ユーザー dot_haraaidot_haraai
提出日時 2021-06-07 23:13:20
言語 Nim
(2.0.2)
結果
AC  
実行時間 572 ms / 4,000 ms
コード長 1,704 bytes
コンパイル時間 6,037 ms
コンパイル使用メモリ 87,360 KB
実行使用メモリ 35,968 KB
最終ジャッジ日時 2024-05-03 23:49:11
合計ジャッジ時間 12,633 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 300 ms
22,616 KB
testcase_12 AC 285 ms
21,532 KB
testcase_13 AC 398 ms
25,344 KB
testcase_14 AC 158 ms
13,440 KB
testcase_15 AC 138 ms
12,288 KB
testcase_16 AC 463 ms
32,000 KB
testcase_17 AC 508 ms
29,312 KB
testcase_18 AC 572 ms
35,712 KB
testcase_19 AC 534 ms
35,968 KB
testcase_20 AC 267 ms
17,792 KB
testcase_21 AC 290 ms
18,176 KB
testcase_22 AC 114 ms
9,856 KB
testcase_23 AC 88 ms
8,448 KB
testcase_24 AC 276 ms
31,104 KB
testcase_25 AC 476 ms
34,912 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]

ソースコード

diff #

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()
0