結果

問題 No.1601 With Animals into Institute
ユーザー 👑 tamatotamato
提出日時 2021-07-10 14:08:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,200 ms / 3,000 ms
コード長 1,334 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 87,328 KB
実行使用メモリ 137,124 KB
最終ジャッジ日時 2023-09-14 19:15:56
合計ジャッジ時間 19,708 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,684 KB
testcase_01 AC 79 ms
71,716 KB
testcase_02 AC 78 ms
71,528 KB
testcase_03 AC 152 ms
79,504 KB
testcase_04 AC 151 ms
79,872 KB
testcase_05 AC 157 ms
79,820 KB
testcase_06 AC 1,090 ms
136,516 KB
testcase_07 AC 1,127 ms
136,608 KB
testcase_08 AC 1,088 ms
137,124 KB
testcase_09 AC 1,129 ms
135,568 KB
testcase_10 AC 1,090 ms
135,120 KB
testcase_11 AC 1,142 ms
135,928 KB
testcase_12 AC 1,200 ms
136,940 KB
testcase_13 AC 1,141 ms
136,092 KB
testcase_14 AC 1,132 ms
136,528 KB
testcase_15 AC 1,156 ms
135,764 KB
testcase_16 AC 1,187 ms
136,388 KB
testcase_17 AC 1,147 ms
135,564 KB
testcase_18 AC 156 ms
79,200 KB
testcase_19 AC 160 ms
79,560 KB
testcase_20 AC 159 ms
79,576 KB
testcase_21 AC 151 ms
78,952 KB
testcase_22 AC 152 ms
79,328 KB
testcase_23 AC 154 ms
79,460 KB
testcase_24 AC 149 ms
79,500 KB
testcase_25 AC 158 ms
79,736 KB
testcase_26 AC 158 ms
79,288 KB
testcase_27 AC 79 ms
71,664 KB
testcase_28 AC 80 ms
71,736 KB
testcase_29 AC 80 ms
71,420 KB
testcase_30 AC 80 ms
71,756 KB
testcase_31 AC 80 ms
71,580 KB
testcase_32 AC 80 ms
71,784 KB
testcase_33 AC 79 ms
71,588 KB
testcase_34 AC 80 ms
71,872 KB
testcase_35 AC 81 ms
71,536 KB
testcase_36 AC 80 ms
71,688 KB
testcase_37 AC 81 ms
71,420 KB
testcase_38 AC 82 ms
71,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline
    import heapq

    def dijkstra(adj, start):
        # adj: [[to, cost] * vertices], 0th index must be empty
        inf = 1 << 60
        dist = [inf] * len(adj)
        dist[start] = 0
        q = []
        heapq.heappush(q, (0, start))
        while q:
            min_dist, v_from = heapq.heappop(q)
            if min_dist > dist[v_from]:
                continue
            v_tos = adj[v_from]
            for v_to, cost in v_tos:
                if min_dist + cost < dist[v_to]:
                    dist[v_to] = min_dist + cost
                    heapq.heappush(q, (dist[v_to], v_to))
        return dist

    N, M = map(int, input().split())
    adj = [[] for _ in range(N*2+1)]
    for _ in range(M):
        a, b, c, x = map(int, input().split())
        if x:
            adj[a].append((b+N, c))
            adj[b].append((a+N, c))
            adj[a+N].append((b+N, c))
            adj[b+N].append((a+N, c))
        else:
            adj[a].append((b, c))
            adj[b].append((a, c))
            adj[a+N].append((b+N, c))
            adj[b+N].append((a+N, c))

    dist = dijkstra(adj, N)
    for i in range(N-1):
        print(dist[i+N+1])
    #print(dist)
    #print(adj)


if __name__ == '__main__':
    main()
0