結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー ああいい
提出日時 2022-01-10 11:46:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,192 KB
実行使用メモリ 117,956 KB
最終ジャッジ日時 2024-11-14 10:45:50
合計ジャッジ時間 18,530 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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