結果

問題 No.748 yuki国のお財布事情
ユーザー compass19compass19
提出日時 2018-10-19 23:00:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,443 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 123,400 KB
最終ジャッジ日時 2023-08-12 02:05:55
合計ジャッジ時間 5,548 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
12,512 KB
testcase_01 AC 16 ms
8,052 KB
testcase_02 AC 17 ms
8,200 KB
testcase_03 AC 16 ms
8,044 KB
testcase_04 AC 15 ms
8,048 KB
testcase_05 AC 16 ms
8,080 KB
testcase_06 AC 16 ms
8,136 KB
testcase_07 AC 16 ms
8,164 KB
testcase_08 AC 16 ms
8,128 KB
testcase_09 AC 16 ms
8,176 KB
testcase_10 AC 16 ms
8,072 KB
testcase_11 AC 16 ms
8,116 KB
testcase_12 AC 16 ms
8,136 KB
testcase_13 AC 296 ms
20,844 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())
citys = {n: {'Root': n, 'child': {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}

# union tree
for e in abs_edges:
	a, b, _ = edges[e]
	# print(a, b)
	if citys[a]['Root'] == a and citys[b]['Root'] == b:
		for c in citys[citys[b]['Root']]['child']:
			citys[c]['Root'] = a
			citys[a]['child'].add(c)
	elif citys[a]['Root'] == a and citys[b]['Root'] != b:
		for c in citys[citys[b]['Root']]['child']:
			citys[c]['Root'] = citys[a]['Root']
			citys[citys[a]['Root']]['child'].add(c)	
	else:
		for c in citys[citys[a]['Root']]['child']:
			citys[c]['Root'] = citys[b]['Root']
			citys[citys[b]['Root']]['child'].add(c)

del_weight = 0
for ix, e in enumerate(sorted_edges):
	# edge eを追加できるかどうか
	a, b, c = edges[e]
	# print(ix+1, a, b, c)
	if citys[a]['Root'] == citys[b]['Root']:
		del_weight += c
		continue
	if citys[a]['Root'] == a and citys[b]['Root'] == b:
		for c in citys[citys[b]['Root']]['child']:
			citys[c]['Root'] = a
			citys[a]['child'].add(c)
	else:
		for c in citys[citys[b]['Root']]['child']:
			citys[c]['Root'] = citys[a]['Root']
			citys[citys[a]['Root']]['child'].add(c)			
print(del_weight)
0