結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー anagohirameanagohirame
提出日時 2020-12-17 00:50:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 82,588 KB
最終ジャッジ日時 2023-10-20 10:10:07
合計ジャッジ時間 19,409 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,444 KB
testcase_01 AC 41 ms
53,444 KB
testcase_02 AC 41 ms
53,444 KB
testcase_03 AC 42 ms
53,444 KB
testcase_04 AC 41 ms
53,444 KB
testcase_05 AC 52 ms
65,244 KB
testcase_06 AC 53 ms
67,292 KB
testcase_07 WA -
testcase_08 AC 150 ms
76,600 KB
testcase_09 AC 910 ms
80,416 KB
testcase_10 WA -
testcase_11 AC 703 ms
79,040 KB
testcase_12 AC 233 ms
77,248 KB
testcase_13 AC 432 ms
78,012 KB
testcase_14 AC 107 ms
76,108 KB
testcase_15 AC 138 ms
76,588 KB
testcase_16 AC 100 ms
75,908 KB
testcase_17 WA -
testcase_18 AC 91 ms
75,896 KB
testcase_19 WA -
testcase_20 AC 82 ms
75,836 KB
testcase_21 AC 608 ms
78,148 KB
testcase_22 AC 41 ms
53,444 KB
testcase_23 WA -
testcase_24 AC 41 ms
53,444 KB
testcase_25 AC 41 ms
53,444 KB
testcase_26 AC 42 ms
53,444 KB
testcase_27 AC 41 ms
53,444 KB
testcase_28 AC 110 ms
76,188 KB
testcase_29 AC 195 ms
76,272 KB
testcase_30 AC 60 ms
66,408 KB
testcase_31 AC 99 ms
75,784 KB
testcase_32 AC 42 ms
53,444 KB
testcase_33 AC 383 ms
77,036 KB
testcase_34 AC 296 ms
77,016 KB
testcase_35 AC 95 ms
75,944 KB
testcase_36 AC 75 ms
72,660 KB
testcase_37 AC 60 ms
66,420 KB
testcase_38 AC 103 ms
76,028 KB
testcase_39 AC 83 ms
74,728 KB
testcase_40 AC 42 ms
53,444 KB
testcase_41 WA -
testcase_42 AC 42 ms
53,444 KB
testcase_43 AC 159 ms
76,948 KB
testcase_44 AC 134 ms
76,908 KB
testcase_45 AC 1,366 ms
82,196 KB
testcase_46 AC 92 ms
75,732 KB
testcase_47 AC 364 ms
76,880 KB
testcase_48 AC 601 ms
79,544 KB
testcase_49 AC 107 ms
76,140 KB
testcase_50 AC 42 ms
53,444 KB
testcase_51 AC 41 ms
53,444 KB
testcase_52 AC 213 ms
77,064 KB
testcase_53 AC 145 ms
76,292 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 TLE -
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)]
	dist[x] = 0
	q = [x]
	while q:
		i, c0 = dec(heappop(q))
		#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))
			else:
				#print("! " + str(j) + " " + str(c1))
				ans = min(ans, c0 + dist[j] + c1)
	#print("-----")

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