結果

問題 No.748 yuki国のお財布事情
ユーザー torikuminotorikumino
提出日時 2018-10-28 19:34:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 500 ms / 2,000 ms
コード長 551 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 103,916 KB
最終ジャッジ日時 2023-08-12 08:08:56
合計ジャッジ時間 7,470 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,200 KB
testcase_01 AC 71 ms
71,060 KB
testcase_02 AC 70 ms
71,396 KB
testcase_03 AC 69 ms
71,412 KB
testcase_04 AC 69 ms
71,396 KB
testcase_05 AC 72 ms
71,200 KB
testcase_06 AC 73 ms
71,416 KB
testcase_07 AC 72 ms
71,268 KB
testcase_08 AC 73 ms
71,376 KB
testcase_09 AC 74 ms
71,556 KB
testcase_10 AC 72 ms
71,360 KB
testcase_11 AC 72 ms
71,120 KB
testcase_12 AC 71 ms
71,484 KB
testcase_13 AC 162 ms
79,648 KB
testcase_14 AC 208 ms
83,348 KB
testcase_15 AC 162 ms
80,216 KB
testcase_16 AC 279 ms
86,328 KB
testcase_17 AC 418 ms
93,124 KB
testcase_18 AC 468 ms
97,980 KB
testcase_19 AC 403 ms
103,916 KB
testcase_20 AC 342 ms
98,656 KB
testcase_21 AC 474 ms
96,940 KB
testcase_22 AC 73 ms
71,200 KB
testcase_23 AC 70 ms
71,424 KB
testcase_24 AC 70 ms
71,520 KB
testcase_25 AC 307 ms
90,040 KB
testcase_26 AC 447 ms
94,784 KB
testcase_27 AC 500 ms
94,516 KB
testcase_28 AC 234 ms
92,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, k = map(int,input().split())
e = []
for _ in range(m):
    a, b, c = map(int,input().split())
    e.append((a-1,b-1,c))
r = 0
for _ in range(k):
    i = int(input())-1
    a, b, c = e[i]
    e[i] = (a,b,0)
p = list(range(n))
s = [1]*n
def f(x):
    if x == p[x]:
        return x
    p[x] = f(p[x])
    return p[x]
def u(x, y):
    x = f(x)
    y = f(y)
    if s[x] > s[y]:
        x, y = y, x
    p[x] = p[y]
    s[y] += s[x]
e.sort(key=lambda x: x[2])
for a, b, c in e:
    if f(a) == f(b):
        r += c
        continue
    u(a, b)
print(r)
0