結果
問題 | No.1601 With Animals into Institute |
ユーザー | LyricalMaestro |
提出日時 | 2024-12-29 17:37:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,272 ms / 3,000 ms |
コード長 | 1,404 bytes |
コンパイル時間 | 780 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 165,696 KB |
最終ジャッジ日時 | 2024-12-29 17:37:51 |
合計ジャッジ時間 | 20,859 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,736 KB |
testcase_01 | AC | 42 ms
52,480 KB |
testcase_02 | AC | 40 ms
52,736 KB |
testcase_03 | AC | 137 ms
78,664 KB |
testcase_04 | AC | 130 ms
78,592 KB |
testcase_05 | AC | 146 ms
78,592 KB |
testcase_06 | AC | 1,129 ms
165,696 KB |
testcase_07 | AC | 1,142 ms
165,316 KB |
testcase_08 | AC | 1,091 ms
164,928 KB |
testcase_09 | AC | 1,270 ms
165,004 KB |
testcase_10 | AC | 1,167 ms
163,844 KB |
testcase_11 | AC | 1,127 ms
164,760 KB |
testcase_12 | AC | 1,226 ms
164,364 KB |
testcase_13 | AC | 1,272 ms
164,876 KB |
testcase_14 | AC | 1,120 ms
163,860 KB |
testcase_15 | AC | 1,228 ms
165,392 KB |
testcase_16 | AC | 1,176 ms
164,352 KB |
testcase_17 | AC | 1,191 ms
164,764 KB |
testcase_18 | AC | 152 ms
78,720 KB |
testcase_19 | AC | 144 ms
79,104 KB |
testcase_20 | AC | 146 ms
78,716 KB |
testcase_21 | AC | 140 ms
78,700 KB |
testcase_22 | AC | 142 ms
79,056 KB |
testcase_23 | AC | 167 ms
78,592 KB |
testcase_24 | AC | 142 ms
78,784 KB |
testcase_25 | AC | 145 ms
78,824 KB |
testcase_26 | AC | 143 ms
78,720 KB |
testcase_27 | AC | 41 ms
52,480 KB |
testcase_28 | AC | 43 ms
52,992 KB |
testcase_29 | AC | 41 ms
52,616 KB |
testcase_30 | AC | 42 ms
53,248 KB |
testcase_31 | AC | 40 ms
52,608 KB |
testcase_32 | AC | 41 ms
52,864 KB |
testcase_33 | AC | 44 ms
52,736 KB |
testcase_34 | AC | 41 ms
52,864 KB |
testcase_35 | AC | 40 ms
52,608 KB |
testcase_36 | AC | 38 ms
52,480 KB |
testcase_37 | AC | 46 ms
52,864 KB |
testcase_38 | AC | 45 ms
52,480 KB |
ソースコード
## https://yukicoder.me/problems/no/1601 import heapq MAX_VALUE = 10 ** 18 def main(): N, M = map(int, input().split()) edges = [] for _ in range(M): a, b, c, x = map(int, input().split()) edges.append((a - 1, b - 1, c, x == 1)) # グラフ構築 next_nodes = [[] for _ in range(2 * N)] for a, b, c, x in edges: if x == 0: next_nodes[a].append((b, c)) next_nodes[b].append((a, c)) next_nodes[a + N].append((b + N, c)) next_nodes[b + N].append((a + N, c)) else: next_nodes[a + N].append((b, c)) next_nodes[b + N].append((a, c)) next_nodes[a + N].append((b + N, c)) next_nodes[b + N].append((a + N, c)) fix = [MAX_VALUE] * (2 * N) seen = [MAX_VALUE] * (2 * N) seen[2 * N - 1] = 0 queue = [] heapq.heappush(queue, (0, 2 * N - 1)) while len(queue) > 0: cost ,v = heapq.heappop(queue) if fix[v] < MAX_VALUE: continue fix[v] = cost for w, c in next_nodes[v]: if fix[w] < MAX_VALUE: continue new_cost = c + cost if seen[w] > new_cost: seen[w] = new_cost heapq.heappush(queue, (new_cost, w)) for i in range(N - 1): print(fix[i]) if __name__ == "__main__": main()