結果
問題 |
No.748 yuki国のお財布事情
|
ユーザー |
![]() |
提出日時 | 2018-10-28 19:34:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 411 ms / 2,000 ms |
コード長 | 551 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 81,972 KB |
実行使用メモリ | 99,700 KB |
最終ジャッジ日時 | 2024-11-19 07:15:18 |
合計ジャッジ時間 | 5,563 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
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)