結果

問題 No.748 yuki国のお財布事情
ユーザー compass19compass19
提出日時 2018-10-20 00:19:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 856 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 48,024 KB
最終ジャッジ日時 2024-04-29 17:38:07
合計ジャッジ時間 13,240 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 33 ms
10,880 KB
testcase_04 AC 32 ms
10,880 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 31 ms
10,752 KB
testcase_08 AC 32 ms
10,624 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 AC 31 ms
10,880 KB
testcase_11 AC 30 ms
10,752 KB
testcase_12 AC 30 ms
10,752 KB
testcase_13 AC 1,007 ms
14,464 KB
testcase_14 RE -
testcase_15 AC 1,756 ms
15,616 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 30 ms
10,752 KB
testcase_23 AC 31 ms
10,752 KB
testcase_24 AC 31 ms
10,752 KB
testcase_25 TLE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, K = map(int, input().split())
Root = [n for n in range(N)]
edges = [None for _ in range(M)]
for m in range(M):
	a, b, c = map(int, input().split())
	edges[m] = (a-1, b-1, c)
abs_edges = set(int(input())-1 for _ in range(K))
sorted_edges = sorted([e for e in set(range(M)) - abs_edges], key=lambda x: edges[x][2])

# 最小木
T = {edges[e] for e in abs_edges}

del_weight = 0
def get_Root(c):
	if Root[c] == c:
		return c
	else:
		return get_Root(Root[c])
def merge(a, b):
	if Root[a] == a:
		Root[get_Root(b)] = a
	elif Root[b] == b:
		Root[get_Root(a)] = b
	else:
		Root[get_Root(b)] = Root[get_Root(a)]

# union tree
for e in abs_edges:
	a, b, c = edges[e]
	merge(a, b)


for e in sorted_edges:
	# edge eを追加できるかどうか
	a, b, c = edges[e]
	if get_Root(a) == get_Root(b):
		del_weight += c
		continue
	merge(a, b)

print(del_weight)
0