結果

問題 No.748 yuki国のお財布事情
ユーザー twkmathtwkmath
提出日時 2018-10-21 13:30:47
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,151 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 32,420 KB
最終ジャッジ日時 2023-08-12 05:42:32
合計ジャッジ時間 7,844 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,088 KB
testcase_01 AC 15 ms
8,088 KB
testcase_02 AC 16 ms
8,144 KB
testcase_03 AC 16 ms
8,220 KB
testcase_04 AC 15 ms
8,136 KB
testcase_05 AC 16 ms
8,096 KB
testcase_06 AC 16 ms
8,060 KB
testcase_07 AC 16 ms
8,096 KB
testcase_08 AC 16 ms
8,136 KB
testcase_09 AC 16 ms
8,080 KB
testcase_10 WA -
testcase_11 AC 15 ms
8,172 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 TLE -
testcase_17 TLE -
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=[int(i) for i in input().split()]
e=[];s=0
for j in range(M):
	a,b,c=[int(i) for i in input().split()]
	e.append((c,a,b))
	s+=c
o=sorted(e)
p={}; pn=0
l=[-1 for _ in range(N+1)]
for j in range(K):
	i=int(input())-1
	a,b=e[i][1:3]
	# x=-1;y=-1
	# for k,q in enumerate(p):
	# 	if a in q: x=k
	# 	if b in q: y=k
	# if x<0 and y<0: p.append({a,b})
	# elif x<0: p[y].add(a)
	# elif y<0: p[x].add(b)
	# elif x!=y: p[x]|=p[y]; del p[y]
	if l[a]<0 and l[b]<0: p[pn]={a,b}; l[a]=pn; l[b]=pn; pn+=1
	elif l[a]<0: p[l[b]].add(a); l[a]=l[b]
	elif l[b]<0: p[l[a]].add(b); l[b]=l[a]
	elif l[a]!=l[b]:
		t=l[b]
		p[l[a]]|=p[t]
		for i in p[t]:
			l[i]=l[a]
		del p[t]
	s-=e[i][0]
for f in o:
	a,b=f[1:3]
	# x=-1;y=-1
	# for k,q in enumerate(p):
	# 	if a in q: x=k
	# 	if b in q: y=k
	# if x<0 and y<0: p.append({a,b})
	# elif x<0: p[y].add(a)
	# elif y<0: p[x].add(b)
	# elif x!=y: p[x]|=p[y]; del p[y]
	if l[a]<0 and l[b]<0: p[pn]={a,b}; l[a]=pn; l[b]=pn; pn+=1
	elif l[a]<0: p[l[b]].add(a); l[a]=l[b]
	elif l[b]<0: p[l[a]].add(b); l[b]=l[a]
	elif l[a]!=l[b]:
		t=l[b]
		p[l[a]]|=p[t]
		for i in p[t]:
			l[i]=l[a]
		del p[t]
	else: continue
	s-=f[0]
print(s)
0