結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー ああいいああいい
提出日時 2022-01-10 11:57:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 947 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 82,820 KB
最終ジャッジ日時 2024-04-26 20:03:12
合計ジャッジ時間 15,868 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,632 KB
testcase_01 AC 39 ms
52,824 KB
testcase_02 AC 39 ms
53,384 KB
testcase_03 AC 38 ms
53,016 KB
testcase_04 AC 40 ms
54,332 KB
testcase_05 AC 39 ms
53,688 KB
testcase_06 AC 40 ms
53,356 KB
testcase_07 AC 74 ms
76,368 KB
testcase_08 AC 98 ms
76,272 KB
testcase_09 AC 922 ms
81,084 KB
testcase_10 AC 95 ms
77,200 KB
testcase_11 AC 717 ms
80,028 KB
testcase_12 AC 221 ms
78,144 KB
testcase_13 AC 401 ms
78,428 KB
testcase_14 AC 48 ms
64,080 KB
testcase_15 AC 97 ms
77,172 KB
testcase_16 AC 191 ms
77,236 KB
testcase_17 AC 61 ms
70,784 KB
testcase_18 AC 57 ms
69,504 KB
testcase_19 AC 461 ms
78,664 KB
testcase_20 AC 45 ms
56,576 KB
testcase_21 AC 882 ms
79,716 KB
testcase_22 AC 39 ms
52,608 KB
testcase_23 AC 39 ms
52,480 KB
testcase_24 AC 39 ms
52,608 KB
testcase_25 AC 38 ms
52,608 KB
testcase_26 AC 39 ms
52,736 KB
testcase_27 AC 38 ms
52,352 KB
testcase_28 AC 55 ms
67,840 KB
testcase_29 AC 147 ms
77,472 KB
testcase_30 AC 49 ms
61,184 KB
testcase_31 AC 83 ms
75,776 KB
testcase_32 AC 38 ms
52,352 KB
testcase_33 AC 307 ms
77,720 KB
testcase_34 AC 192 ms
77,068 KB
testcase_35 AC 149 ms
77,032 KB
testcase_36 AC 121 ms
76,800 KB
testcase_37 AC 98 ms
76,288 KB
testcase_38 AC 167 ms
76,648 KB
testcase_39 AC 147 ms
77,140 KB
testcase_40 AC 38 ms
53,316 KB
testcase_41 AC 40 ms
52,864 KB
testcase_42 AC 38 ms
52,468 KB
testcase_43 AC 127 ms
77,696 KB
testcase_44 AC 116 ms
77,312 KB
testcase_45 AC 840 ms
80,408 KB
testcase_46 AC 81 ms
75,920 KB
testcase_47 AC 175 ms
77,164 KB
testcase_48 AC 557 ms
79,464 KB
testcase_49 AC 87 ms
76,160 KB
testcase_50 AC 39 ms
52,480 KB
testcase_51 AC 39 ms
52,352 KB
testcase_52 AC 206 ms
76,820 KB
testcase_53 AC 139 ms
76,544 KB
testcase_54 AC 757 ms
81,316 KB
testcase_55 AC 745 ms
81,980 KB
testcase_56 AC 754 ms
81,908 KB
testcase_57 AC 947 ms
82,820 KB
testcase_58 AC 944 ms
82,300 KB
testcase_59 AC 930 ms
82,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
N,M = map(int,input().split())
G = [[] for _ in range(N+1)]
edge = []
for _ in range(M):
    u,v,w = map(int,input().split())
    G[u].append((v,w))
    if T == 0:
        G[v].append((u,w))
    edge.append((u,v,w))

import heapq
q = []
heapq.heapify(q)
INF = 10 ** 15
_min = INF
def check(e):
    global _min
    dist = [INF] * (N + 1)
    start,end,w = e
    dist[end] = 0
    heapq.heappush(q,(0,end))
    while q:
        d,now = heapq.heappop(q)
        #if now == start:break
        if d > dist[now]:continue
        for v,ww in  G[now]:
            if dist[v] > d + ww:
                if now != end or v != start:
                    dist[v] = d + ww
                    heapq.heappush(q,(d+ww,v))
    if dist[start] + w < _min:
        _min = dist[start] + w
for e in edge:
    check(e)
if _min == INF:
    print(-1)
else:
    print(_min)
0