結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー anagohirameanagohirame
提出日時 2020-12-17 00:42:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,024 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 81,764 KB
実行使用メモリ 84,740 KB
最終ジャッジ日時 2023-10-20 10:07:41
合計ジャッジ時間 15,529 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,500 KB
testcase_01 AC 41 ms
53,468 KB
testcase_02 AC 41 ms
53,468 KB
testcase_03 AC 42 ms
53,468 KB
testcase_04 AC 41 ms
53,468 KB
testcase_05 AC 55 ms
69,396 KB
testcase_06 AC 57 ms
71,444 KB
testcase_07 AC 131 ms
76,180 KB
testcase_08 AC 186 ms
76,856 KB
testcase_09 WA -
testcase_10 AC 145 ms
76,632 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 126 ms
76,468 KB
testcase_15 AC 159 ms
76,712 KB
testcase_16 WA -
testcase_17 AC 106 ms
76,084 KB
testcase_18 AC 102 ms
75,976 KB
testcase_19 AC 326 ms
77,964 KB
testcase_20 AC 87 ms
75,712 KB
testcase_21 AC 711 ms
78,996 KB
testcase_22 AC 40 ms
53,468 KB
testcase_23 AC 41 ms
53,468 KB
testcase_24 AC 40 ms
53,468 KB
testcase_25 AC 40 ms
53,468 KB
testcase_26 AC 41 ms
53,468 KB
testcase_27 AC 41 ms
53,468 KB
testcase_28 AC 126 ms
76,312 KB
testcase_29 AC 209 ms
76,416 KB
testcase_30 AC 57 ms
64,256 KB
testcase_31 AC 100 ms
75,784 KB
testcase_32 AC 41 ms
53,468 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 66 ms
68,372 KB
testcase_36 AC 72 ms
70,568 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 40 ms
53,468 KB
testcase_42 AC 40 ms
53,468 KB
testcase_43 AC 180 ms
77,116 KB
testcase_44 AC 139 ms
76,668 KB
testcase_45 AC 1,390 ms
84,740 KB
testcase_46 AC 95 ms
75,780 KB
testcase_47 AC 380 ms
77,248 KB
testcase_48 AC 450 ms
79,052 KB
testcase_49 AC 109 ms
76,152 KB
testcase_50 AC 42 ms
53,468 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
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]

def enc(pos, cost):
	return cost * 10000 + pos

def dec(x):
	return x % 10000, x // 10000

INF = 10**18
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(enc(v-1, w))
	if t == 0:
		adj[v-1].append(enc(u-1, w))

ans = INF
for x in range(n):
	dist = [INF for _ in range(n)]
	prev = [-1 for _ in range(n)]
	visited = [False for _ in range(n)]
	dist[x] = 0
	q = [x]
	flg = False
	while q:
		i, c0 = dec(heappop(q))
		visited[i] = True
		#print(i, c0)
		for y in adj[i]:
			j, c1 = dec(y)
			if t == 0 and prev[i] == j:
				continue
			if dist[j] > c0 + c1:
				prev[j] = i
				dist[j] = c0 + c1
				heappush(q, enc(j, c0 + c1))
			elif visited[j] and j == x:
				#print("! " + str(j) + " " + str(c1))
				ans = min(ans, c0 + c1)
				flg = True
		if flg:
			break
	#print("-----")

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