結果

問題 No.160 最短経路のうち辞書順最小
ユーザー 6soukiti296soukiti29
提出日時 2017-09-23 09:48:08
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 2,473 bytes
コンパイル時間 3,337 ms
コンパイル使用メモリ 72,068 KB
実行使用メモリ 16,472 KB
最終ジャッジ日時 2023-09-12 15:13:41
合計ジャッジ時間 6,261 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 5 ms
4,384 KB
testcase_05 AC 9 ms
4,380 KB
testcase_06 AC 12 ms
4,380 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 4 ms
4,380 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(37, 25) Warning: Number of spaces around '<=' is not consistent [Spacing]

ソースコード

diff #

import sequtils,strutils

proc `<`(A, B : openarray[int]) : bool=
    var
        i : int
    while true:
        if A[i] < B[i]:
            return false
        elif A[i] > B[i]:
            return true
        else:
            i += 1
proc `<=`(A, B : openarray[int]) : bool =
    return A < B
    
type
    priorityQue[I:static[int];T:tuple] = array[I + 1,T]
    item = tuple[id : int; cost : seq[int]]
    dist = tuple[s, d : int]
proc push[T](A:var priorityQue; b: T;)=
    const key = 1
    A[0][0] += 1
    A[A[0][0]] = b # A[0][0]はsize、最大のIndex
    var index = A[0][0]
    while index > 1 and A[index][key] > A[index div 2][key]:
        (A[index],A[index div 2]) = (A[index div 2],A[index])
        index = index div 2
proc pop(A: var priorityQue):item = 
    const key = 1
    result = A[1]
    A[1] = A[A[0][0]]
    var a : item
    A[A[0][0]] = a
    A[0][0] -= 1
    var index = 1
    while index * 2 <= A[0][0]:
        if index * 2 + 1<= A[0][0]:
            if A[index][key] < A[index * 2][key] and A[index * 2 + 1][key] <= A[index * 2][key]:
                (A[index],A[index * 2]) = (A[index * 2],A[index])
                index = index * 2
            elif A[index][key] < A[index * 2 + 1][key]:
                (A[index],A[index * 2 + 1]) = (A[index * 2 + 1],A[index])
                index = index * 2 + 1
            else:
                break
        elif index * 2 <= A[0][0]:
            if A[index][key] < A[index * 2][key]:
                (A[index],A[index * 2]) = (A[index * 2],A[index])
            break
        else:
            break
proc size(A : priorityQue):int=
    return A[0][0]
    
var
    N,M,S,G : int
    a,b,c : int
    
(N, M, S, G) = stdin.readline.split.map(parseInt)
var hyou = newSeqWith(N + 1, newSeq[dist](0))

for m in 1..M:
    (a, b, c) = stdin.readline.split.map(parseInt)
    hyou[a].add((b, c))
    hyou[b].add((a, c))
    
var
    pq : priorityque[40000,item]
    t : item
    mincos : array[201, int]

for i in 0..200:
    mincos[i] = int.high
block tansaku:
    pq.push((S, @[0, S]))
    while pq.size > 0:
        t = pq.pop
        var c = t.cost[0]
        if t.id == G:
            echo t.cost[1..t.cost.high].join(" ")
            break tansaku
        for p in hyou[t.id]:
            if c + p.d <= mincos[p.s]:
                mincos[p.s] = c + p.d
                var q = t
                q.cost[0] += p.d
                q.id = p.s
                q.cost.add(p.s)
                pq.push(q)
0