結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー ああいいああいい
提出日時 2022-01-10 11:46:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 117,892 KB
最終ジャッジ日時 2024-04-26 20:02:48
合計ジャッジ時間 18,724 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,608 KB
testcase_01 AC 40 ms
52,480 KB
testcase_02 AC 39 ms
52,480 KB
testcase_03 AC 40 ms
52,608 KB
testcase_04 AC 39 ms
52,224 KB
testcase_05 AC 40 ms
52,352 KB
testcase_06 AC 40 ms
52,352 KB
testcase_07 AC 76 ms
76,032 KB
testcase_08 AC 103 ms
76,416 KB
testcase_09 AC 1,017 ms
82,220 KB
testcase_10 AC 96 ms
76,800 KB
testcase_11 AC 800 ms
80,692 KB
testcase_12 WA -
testcase_13 AC 432 ms
78,884 KB
testcase_14 AC 47 ms
63,232 KB
testcase_15 AC 98 ms
77,104 KB
testcase_16 AC 199 ms
77,312 KB
testcase_17 AC 61 ms
71,168 KB
testcase_18 AC 58 ms
69,504 KB
testcase_19 AC 485 ms
78,488 KB
testcase_20 AC 45 ms
56,448 KB
testcase_21 AC 969 ms
85,584 KB
testcase_22 AC 38 ms
52,608 KB
testcase_23 AC 37 ms
52,480 KB
testcase_24 AC 39 ms
52,864 KB
testcase_25 AC 39 ms
52,608 KB
testcase_26 AC 39 ms
52,480 KB
testcase_27 AC 39 ms
52,864 KB
testcase_28 AC 54 ms
67,584 KB
testcase_29 AC 146 ms
76,972 KB
testcase_30 AC 49 ms
61,184 KB
testcase_31 AC 79 ms
75,668 KB
testcase_32 AC 40 ms
52,992 KB
testcase_33 AC 307 ms
77,460 KB
testcase_34 AC 189 ms
77,324 KB
testcase_35 AC 168 ms
78,464 KB
testcase_36 AC 163 ms
77,152 KB
testcase_37 AC 93 ms
76,032 KB
testcase_38 WA -
testcase_39 AC 139 ms
76,908 KB
testcase_40 AC 39 ms
52,992 KB
testcase_41 AC 40 ms
52,736 KB
testcase_42 AC 40 ms
52,864 KB
testcase_43 AC 130 ms
77,512 KB
testcase_44 AC 118 ms
77,312 KB
testcase_45 AC 842 ms
80,656 KB
testcase_46 AC 93 ms
75,776 KB
testcase_47 AC 176 ms
77,204 KB
testcase_48 AC 963 ms
80,724 KB
testcase_49 AC 211 ms
76,416 KB
testcase_50 AC 40 ms
52,480 KB
testcase_51 AC 39 ms
52,608 KB
testcase_52 AC 283 ms
77,264 KB
testcase_53 AC 182 ms
77,016 KB
testcase_54 AC 751 ms
81,420 KB
testcase_55 AC 760 ms
81,748 KB
testcase_56 AC 735 ms
81,572 KB
testcase_57 AC 1,366 ms
117,344 KB
testcase_58 AC 1,381 ms
117,892 KB
testcase_59 AC 1,414 ms
117,032 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