結果

問題 No.807 umg tours
ユーザー dot_haraaidot_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
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
/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