結果

問題 No.748 yuki国のお財布事情
ユーザー twkmathtwkmath
提出日時 2018-10-21 12:36:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 656 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 13,928 KB
最終ジャッジ日時 2023-08-12 05:40:40
合計ジャッジ時間 5,786 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,340 KB
testcase_01 AC 15 ms
7,876 KB
testcase_02 AC 16 ms
7,984 KB
testcase_03 AC 15 ms
7,916 KB
testcase_04 AC 15 ms
7,824 KB
testcase_05 AC 16 ms
7,876 KB
testcase_06 AC 16 ms
8,292 KB
testcase_07 AC 16 ms
8,336 KB
testcase_08 AC 16 ms
8,012 KB
testcase_09 AC 16 ms
7,916 KB
testcase_10 AC 15 ms
7,872 KB
testcase_11 AC 16 ms
7,992 KB
testcase_12 AC 16 ms
8,304 KB
testcase_13 AC 108 ms
11,048 KB
testcase_14 AC 882 ms
13,928 KB
testcase_15 AC 155 ms
11,500 KB
testcase_16 TLE -
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=[int(i) for i in input().split()]
e=[];t=set();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=[]
for j in range(K):
	i=int(input())-1
	t.add(i)
	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]
	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]
	else: continue
	s-=f[0]
print(s)
0