結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
10,624 KB
testcase_04 AC 30 ms
10,624 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 31 ms
10,624 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 31 ms
10,752 KB
testcase_10 AC 31 ms
10,752 KB
testcase_11 AC 31 ms
10,624 KB
testcase_12 AC 31 ms
10,624 KB
testcase_13 AC 110 ms
14,592 KB
testcase_14 AC 181 ms
18,992 KB
testcase_15 AC 124 ms
15,616 KB
testcase_16 AC 324 ms
25,072 KB
testcase_17 AC 624 ms
39,184 KB
testcase_18 AC 739 ms
42,884 KB
testcase_19 AC 810 ms
48,516 KB
testcase_20 AC 734 ms
45,448 KB
testcase_21 AC 747 ms
43,288 KB
testcase_22 AC 31 ms
10,752 KB
testcase_23 AC 31 ms
10,752 KB
testcase_24 AC 31 ms
10,880 KB
testcase_25 AC 593 ms
34,780 KB
testcase_26 AC 732 ms
44,068 KB
testcase_27 AC 713 ms
43,064 KB
testcase_28 AC 548 ms
33,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, K = map(int, input().split())
Root = [n for n in range(N)]
Root_num = [1 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):
	root_a = get_Root(a)
	root_b = get_Root(b)
	if Root_num[root_a] < Root_num[root_b]:
		Root[root_a] = Root[root_b]
		Root_num[root_b] += Root_num[root_a]
	else:
		Root[root_b] = Root[root_a]
		Root_num[root_a] += Root_num[root_b]		

# 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