結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー anagohirameanagohirame
提出日時 2020-12-17 00:59:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 813 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 82,464 KB
最終ジャッジ日時 2023-10-20 10:12:04
合計ジャッジ時間 13,837 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,500 KB
testcase_01 AC 38 ms
53,500 KB
testcase_02 AC 40 ms
53,500 KB
testcase_03 AC 39 ms
53,500 KB
testcase_04 AC 38 ms
53,500 KB
testcase_05 AC 48 ms
65,228 KB
testcase_06 AC 48 ms
67,276 KB
testcase_07 AC 101 ms
75,968 KB
testcase_08 AC 144 ms
76,600 KB
testcase_09 AC 847 ms
80,388 KB
testcase_10 AC 119 ms
76,352 KB
testcase_11 AC 669 ms
78,796 KB
testcase_12 AC 218 ms
76,896 KB
testcase_13 AC 404 ms
78,052 KB
testcase_14 AC 98 ms
75,836 KB
testcase_15 AC 120 ms
76,428 KB
testcase_16 AC 90 ms
75,860 KB
testcase_17 AC 88 ms
75,908 KB
testcase_18 AC 84 ms
75,784 KB
testcase_19 AC 320 ms
77,384 KB
testcase_20 AC 77 ms
75,852 KB
testcase_21 AC 576 ms
78,108 KB
testcase_22 AC 38 ms
53,500 KB
testcase_23 AC 38 ms
53,500 KB
testcase_24 AC 39 ms
53,500 KB
testcase_25 AC 38 ms
53,500 KB
testcase_26 AC 39 ms
53,500 KB
testcase_27 AC 39 ms
53,500 KB
testcase_28 AC 98 ms
76,208 KB
testcase_29 AC 177 ms
76,196 KB
testcase_30 AC 52 ms
64,264 KB
testcase_31 AC 87 ms
75,664 KB
testcase_32 AC 38 ms
53,500 KB
testcase_33 AC 323 ms
76,788 KB
testcase_34 AC 265 ms
76,652 KB
testcase_35 AC 90 ms
75,804 KB
testcase_36 AC 70 ms
70,520 KB
testcase_37 AC 54 ms
64,280 KB
testcase_38 AC 93 ms
75,804 KB
testcase_39 AC 78 ms
73,940 KB
testcase_40 AC 39 ms
53,500 KB
testcase_41 AC 40 ms
53,500 KB
testcase_42 AC 39 ms
53,500 KB
testcase_43 AC 150 ms
76,844 KB
testcase_44 AC 130 ms
76,652 KB
testcase_45 AC 1,285 ms
82,132 KB
testcase_46 AC 81 ms
75,620 KB
testcase_47 AC 340 ms
76,732 KB
testcase_48 AC 561 ms
79,768 KB
testcase_49 AC 97 ms
76,036 KB
testcase_50 AC 38 ms
53,500 KB
testcase_51 AC 38 ms
53,500 KB
testcase_52 AC 190 ms
76,436 KB
testcase_53 AC 140 ms
76,308 KB
testcase_54 TLE -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

INF = 10**16
t = int(input())
n, m = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(m):
	u, v, w = map(int, input().split())
	adj[u-1].append(w * 3000 + v-1)
	if t == 0:
		adj[v-1].append(w * 3000 + u-1)

ans = INF
for x in range(n):
	dist = [INF for _ in range(n)]
	prev = [-1 for _ in range(n)]
	dist[x] = 0
	q = [x]
	while q:
		z = heappop(q)
		i, c0 = z % 3000, z // 3000
		for y in adj[i]:
			j, c1 = y % 3000, y // 3000
			if t == 0 and prev[i] == j:
				continue
			if dist[j] > c0 + c1:
				prev[j] = i
				dist[j] = c0 + c1
				heappush(q, j + (c0 + c1) * 3000)
			else:
				if t == 0 or j == x:
					ans = min(ans, c0 + dist[j] + c1)

if ans == INF:
	print(-1)
else:
	print(ans)
0