結果
問題 | No.1320 Two Type Min Cost Cycle |
ユーザー | rlangevin |
提出日時 | 2024-02-10 13:49:19 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,904 bytes |
コンパイル時間 | 310 ms |
コンパイル使用メモリ | 82,536 KB |
実行使用メモリ | 111,620 KB |
最終ジャッジ日時 | 2024-09-28 17:10:55 |
合計ジャッジ時間 | 20,854 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
53,148 KB |
testcase_01 | AC | 34 ms
53,464 KB |
testcase_02 | AC | 33 ms
53,200 KB |
testcase_03 | AC | 35 ms
53,144 KB |
testcase_04 | AC | 36 ms
54,088 KB |
testcase_05 | AC | 39 ms
61,340 KB |
testcase_06 | AC | 40 ms
63,012 KB |
testcase_07 | AC | 98 ms
76,900 KB |
testcase_08 | AC | 182 ms
77,884 KB |
testcase_09 | AC | 1,394 ms
98,472 KB |
testcase_10 | AC | 124 ms
77,168 KB |
testcase_11 | AC | 1,124 ms
94,592 KB |
testcase_12 | AC | 334 ms
79,832 KB |
testcase_13 | AC | 630 ms
85,040 KB |
testcase_14 | AC | 98 ms
76,784 KB |
testcase_15 | AC | 121 ms
77,064 KB |
testcase_16 | AC | 96 ms
77,004 KB |
testcase_17 | AC | 77 ms
76,712 KB |
testcase_18 | AC | 77 ms
76,284 KB |
testcase_19 | AC | 379 ms
80,372 KB |
testcase_20 | AC | 81 ms
77,188 KB |
testcase_21 | AC | 823 ms
85,904 KB |
testcase_22 | AC | 33 ms
54,516 KB |
testcase_23 | AC | 32 ms
53,820 KB |
testcase_24 | AC | 32 ms
53,264 KB |
testcase_25 | AC | 32 ms
53,316 KB |
testcase_26 | AC | 32 ms
53,548 KB |
testcase_27 | AC | 34 ms
53,080 KB |
testcase_28 | AC | 117 ms
76,916 KB |
testcase_29 | AC | 290 ms
77,692 KB |
testcase_30 | AC | 45 ms
64,436 KB |
testcase_31 | AC | 95 ms
77,192 KB |
testcase_32 | AC | 36 ms
55,012 KB |
testcase_33 | AC | 905 ms
87,464 KB |
testcase_34 | AC | 528 ms
83,344 KB |
testcase_35 | AC | 91 ms
76,600 KB |
testcase_36 | AC | 67 ms
74,188 KB |
testcase_37 | AC | 57 ms
67,472 KB |
testcase_38 | AC | 89 ms
76,796 KB |
testcase_39 | AC | 77 ms
76,652 KB |
testcase_40 | AC | 34 ms
53,612 KB |
testcase_41 | AC | 34 ms
53,912 KB |
testcase_42 | AC | 34 ms
54,344 KB |
testcase_43 | AC | 153 ms
77,608 KB |
testcase_44 | AC | 126 ms
77,104 KB |
testcase_45 | TLE | - |
testcase_46 | AC | 88 ms
76,940 KB |
testcase_47 | AC | 768 ms
85,524 KB |
testcase_48 | AC | 597 ms
83,076 KB |
testcase_49 | AC | 106 ms
76,876 KB |
testcase_50 | AC | 33 ms
54,108 KB |
testcase_51 | AC | 33 ms
54,936 KB |
testcase_52 | AC | 262 ms
78,960 KB |
testcase_53 | AC | 166 ms
77,512 KB |
testcase_54 | AC | 571 ms
83,896 KB |
testcase_55 | AC | 581 ms
83,764 KB |
testcase_56 | AC | 578 ms
84,452 KB |
testcase_57 | AC | 1,408 ms
101,932 KB |
testcase_58 | AC | 1,391 ms
101,944 KB |
testcase_59 | AC | 1,371 ms
102,060 KB |
ソースコード
import sys input = sys.stdin.readline from heapq import heappush, heappop inf = 10**18 def dijkstra(s, t): # ゴールがない場合はg=-1とする。 N = len(G) def cost(v, m): return v * N + m dist = [inf] * N mindist = [inf] * N seen = [False] * N Edge = set() Q = [(cost(0, s), -1)] while Q: c, p = heappop(Q) c, m = divmod(c, N) if seen[m]: continue seen[m] = True dist[m] = c if t == 0 and p != -1: Edge.add(DD[(m,p)]) #------heapをアップデートする。-------- for u, C in G[m]: if seen[u]: continue newdist = dist[m] + C #------------------------------------ if newdist >= mindist[u]: continue mindist[u] = newdist heappush(Q, (cost(newdist, u), m)) return dist, Edge T = int(input()) N, M = map(int, input().split()) G = [[] for i in range(N)] E = [] if T == 0: DD = dict() for i in range(M): u, v, c = map(int, input().split()) u, v = u - 1, v - 1 G[u].append((v, c)) G[v].append((u, c)) E.append((u, v, c)) DD[(u, v)] = i DD[(v, u)] = i ans = inf for s in range(N): D, Edge = dijkstra(s, T) for i in range(M): u, v, c = E[i] if i in Edge: continue ans = min(ans, D[u] + D[v] + c) else: for i in range(M): u, v, c = map(int, input().split()) u, v = u - 1, v - 1 G[u].append((v, c)) E.append((u, v, c)) ans = inf for s in range(N): D, Edge = dijkstra(s, T) for i in range(M): u, v, c = E[i] if v != s: continue ans = min(ans, D[u] + c) print(ans) if ans != inf else print(-1)