結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-30 23:25:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 953 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 82,944 KB
最終ジャッジ日時 2024-04-17 00:06:01
合計ジャッジ時間 16,375 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,992 KB
testcase_01 AC 47 ms
52,864 KB
testcase_02 AC 45 ms
52,224 KB
testcase_03 AC 44 ms
52,352 KB
testcase_04 AC 44 ms
52,608 KB
testcase_05 AC 43 ms
52,736 KB
testcase_06 AC 43 ms
52,736 KB
testcase_07 AC 79 ms
76,032 KB
testcase_08 AC 108 ms
76,544 KB
testcase_09 AC 695 ms
79,232 KB
testcase_10 AC 89 ms
76,672 KB
testcase_11 AC 619 ms
79,360 KB
testcase_12 AC 216 ms
78,336 KB
testcase_13 AC 382 ms
79,232 KB
testcase_14 AC 54 ms
62,336 KB
testcase_15 AC 104 ms
76,800 KB
testcase_16 AC 181 ms
77,184 KB
testcase_17 AC 67 ms
69,888 KB
testcase_18 AC 62 ms
67,840 KB
testcase_19 AC 419 ms
78,464 KB
testcase_20 AC 53 ms
60,672 KB
testcase_21 AC 756 ms
80,384 KB
testcase_22 AC 45 ms
52,608 KB
testcase_23 AC 45 ms
52,608 KB
testcase_24 AC 44 ms
52,480 KB
testcase_25 AC 44 ms
52,736 KB
testcase_26 AC 44 ms
52,352 KB
testcase_27 AC 44 ms
52,864 KB
testcase_28 AC 64 ms
68,992 KB
testcase_29 WA -
testcase_30 AC 58 ms
61,696 KB
testcase_31 AC 90 ms
76,160 KB
testcase_32 AC 44 ms
52,480 KB
testcase_33 WA -
testcase_34 AC 199 ms
77,312 KB
testcase_35 AC 154 ms
77,056 KB
testcase_36 AC 131 ms
76,800 KB
testcase_37 AC 110 ms
76,288 KB
testcase_38 AC 154 ms
76,928 KB
testcase_39 AC 138 ms
77,184 KB
testcase_40 AC 44 ms
52,736 KB
testcase_41 AC 44 ms
52,864 KB
testcase_42 AC 43 ms
52,736 KB
testcase_43 AC 138 ms
77,568 KB
testcase_44 AC 123 ms
77,056 KB
testcase_45 AC 981 ms
80,384 KB
testcase_46 AC 91 ms
76,416 KB
testcase_47 AC 180 ms
77,696 KB
testcase_48 AC 522 ms
79,232 KB
testcase_49 AC 101 ms
76,288 KB
testcase_50 AC 44 ms
52,480 KB
testcase_51 AC 43 ms
52,736 KB
testcase_52 AC 241 ms
77,056 KB
testcase_53 AC 199 ms
77,184 KB
testcase_54 AC 829 ms
81,408 KB
testcase_55 AC 814 ms
81,280 KB
testcase_56 AC 827 ms
82,048 KB
testcase_57 AC 879 ms
81,792 KB
testcase_58 AC 887 ms
82,944 KB
testcase_59 AC 869 ms
82,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import heapq
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**12

T = int(input())
N, M = map(int, input().split())
edge = []
G = [[] for _ in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edge.append((a, b, c))
    G[a].append((b, c))
    if T == 0:
        G[b].append((a, c))


def dijkstra(i):
    s, t, c = edge[i]
    dist = [inf] * N
    dist[t] = 0
    que = [(0, t)]
    while que:
        dv, v = heapq.heappop(que)
        if dist[v] < dv:
            continue
        if v == s:
            break
        for u, du in G[v]:
            if (v, u) in ((s, t), (t, s)):
                continue
            if dist[u] > dv + du:
                dist[u] = dv + du
                heapq.heappush(que, (dv + du, u))
    return c + dist[s]


ans = inf
for i in range(M):
    d = dijkstra(i)
    if d < ans:
        ans = d
if ans >= inf:
    ans = -1
print(ans)
0