結果

問題 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
コンパイル時間 107 ms
コンパイル使用メモリ 11,072 KB
実行使用メモリ 45,500 KB
最終ジャッジ日時 2023-08-12 03:01:55
合計ジャッジ時間 11,774 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,288 KB
testcase_01 AC 17 ms
8,296 KB
testcase_02 AC 17 ms
8,328 KB
testcase_03 AC 16 ms
8,292 KB
testcase_04 AC 15 ms
8,328 KB
testcase_05 AC 16 ms
8,204 KB
testcase_06 AC 16 ms
8,332 KB
testcase_07 AC 16 ms
8,296 KB
testcase_08 AC 16 ms
8,240 KB
testcase_09 AC 16 ms
8,188 KB
testcase_10 AC 16 ms
7,860 KB
testcase_11 AC 16 ms
8,204 KB
testcase_12 AC 16 ms
8,292 KB
testcase_13 AC 851 ms
12,128 KB
testcase_14 RE -
testcase_15 AC 1,526 ms
13,156 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 15 ms
8,296 KB
testcase_23 AC 16 ms
8,228 KB
testcase_24 AC 16 ms
8,220 KB
testcase_25 AC 1,859 ms
32,300 KB
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