結果

問題 No.748 yuki国のお財布事情
ユーザー compass19compass19
提出日時 2018-10-19 23:35:58
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 1,669 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 256,932 KB
最終ジャッジ日時 2023-08-12 02:30:48
合計ジャッジ時間 4,653 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,060 KB
testcase_01 AC 16 ms
8,040 KB
testcase_02 AC 16 ms
8,044 KB
testcase_03 AC 17 ms
8,124 KB
testcase_04 AC 16 ms
8,080 KB
testcase_05 AC 16 ms
8,164 KB
testcase_06 AC 16 ms
8,168 KB
testcase_07 AC 16 ms
8,212 KB
testcase_08 AC 16 ms
8,044 KB
testcase_09 AC 17 ms
8,096 KB
testcase_10 AC 16 ms
8,108 KB
testcase_11 AC 17 ms
8,116 KB
testcase_12 AC 16 ms
8,168 KB
testcase_13 AC 155 ms
20,304 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, K = map(int, input().split())
Root = [n for n in range(N)]
Children = [{n} for n in range(N)]
edges = [None for _ in range(M)]
total_cost = 0
for m in range(M):
	a, b, c = map(int, input().split())
	edges[m] = (a-1, b-1, c)
	total_cost += 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

# union tree
for e in abs_edges:
	a, b, c = edges[e]
	total_cost -= c
	if Root[a] == a and Root[b] == b:
		Children[a] |= Children[Root[b]]
		for c in Children[Root[b]]:
			Root[c] = a
	elif Root[a] == a and Root[b] != b:
		Children[Root[a]] |= Children[Root[b]]	
		for c in Children[Root[b]]:
			Root[c] = Root[a]
	else:
		Children[Root[b]] |= Children[Root[a]]
		for c in Children[Root[a]]:
			Root[c] = Root[b]

is_finish = False

for n in range(N):
	if len(Children[n]) == N:
		is_finish = True

for e in sorted_edges:
	if is_finish:
		break
	# edge eを追加できるかどうか
	a, b, c = edges[e]
	if Root[a] == Root[b]:
		continue
	else:
		total_cost -= c
	# 	del_weight += c
	# 	continue
	if Root[a] == a and Root[b] == b:
		Children[a] |= Children[Root[b]]
		for c in Children[Root[b]]:
			Root[c] = a
		if len(Children[a]) == N:
			is_finish = True
	elif Root[a] == a and Root[b] != b:
		Children[Root[a]] |= Children[Root[b]]
		for c in Children[Root[b]]:
			Root[c] = Root[a]
		if len(Children[Root[a]]) == N:
			is_finish = True	
	else:
		Children[Root[b]] |= Children[Root[a]]
		for c in Children[Root[a]]:
			Root[c] = Root[b]
		if len(Children[Root[b]]) == N:
			is_finish = True

print(total_cost)
0