結果

問題 No.748 yuki国のお財布事情
ユーザー ああいいああいい
提出日時 2022-06-12 19:56:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 526 ms / 2,000 ms
コード長 755 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 81,520 KB
実行使用メモリ 103,296 KB
最終ジャッジ日時 2023-10-24 14:07:07
合計ジャッジ時間 7,832 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,348 KB
testcase_01 AC 37 ms
53,348 KB
testcase_02 AC 36 ms
53,348 KB
testcase_03 AC 35 ms
53,348 KB
testcase_04 AC 34 ms
53,348 KB
testcase_05 AC 39 ms
53,348 KB
testcase_06 AC 35 ms
53,348 KB
testcase_07 AC 35 ms
53,348 KB
testcase_08 AC 34 ms
53,348 KB
testcase_09 AC 35 ms
53,348 KB
testcase_10 AC 34 ms
53,348 KB
testcase_11 AC 36 ms
53,348 KB
testcase_12 AC 35 ms
53,348 KB
testcase_13 AC 159 ms
78,536 KB
testcase_14 AC 221 ms
81,424 KB
testcase_15 AC 164 ms
79,344 KB
testcase_16 AC 360 ms
86,248 KB
testcase_17 AC 378 ms
92,808 KB
testcase_18 AC 497 ms
97,528 KB
testcase_19 AC 453 ms
103,296 KB
testcase_20 AC 431 ms
100,428 KB
testcase_21 AC 495 ms
96,364 KB
testcase_22 AC 35 ms
53,348 KB
testcase_23 AC 33 ms
53,348 KB
testcase_24 AC 33 ms
53,348 KB
testcase_25 AC 266 ms
90,988 KB
testcase_26 AC 489 ms
95,100 KB
testcase_27 AC 526 ms
95,236 KB
testcase_28 AC 311 ms
95,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 8)

N,M,K = map(int,input().split())
edge = []
for _ in range(M):
    a,b,c = map(int,input().split())
    edge.append((c,a,b,_))
parent = list(range(N + 1))
def find(i):
    if parent[i] == i:
        return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:
        return False
    parent[I] = J
    parent[i] = J
    return True
def isSame(i,j):
    return find(i) == find(j)

ans = 0
s = set()
for _ in range(K):
    e = int(input())
    c,a,b,i = edge[e - 1]
    unite(a,b)
    s.add(e - 1)
edge.sort(key = lambda x:x[0])
for c,a,b,_ in edge:
    if _ in s:continue
    if isSame(a,b):
        ans += c
    else:
        unite(a,b)
print(ans)
0