結果
問題 | No.748 yuki国のお財布事情 |
ユーザー |
|
提出日時 | 2021-01-05 09:41:04 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,090 bytes |
コンパイル時間 | 87 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 123,732 KB |
最終ジャッジ日時 | 2024-10-15 16:29:08 |
合計ジャッジ時間 | 35,045 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 RE * 1 |
ソースコード
import sysfrom collections import defaultdictimport numpy as npfrom scipy.sparse.csgraph import connected_components, minimum_spanning_treefrom scipy.sparse import csr_matrixinput = sys.stdin.buffer.readlineMAX = 10 ** 10N, M, K = map(int, input().split())ABC = np.array([tuple(map(int, input().split())) for _ in range(M)], dtype=np.int64)ABC[:, :2] -= 1ans = ABC[:, 2].sum()if K:E = np.array([int(input()) - 1 for _ in range(K)])frm = ABC[E, 0]to = ABC[E, 1]ans -= ABC[E, 2].sum()connection = csr_matrix(([1] * K, (frm, to)), shape=(N, N))compress_N, labels = connected_components(connection)ABC[:, :2] = labels[ABC[:, :2]]else:compress_N = Nd = defaultdict(lambda: MAX)for a, b, c in ABC:if a == b:continueif a > b: a, b = b, ad[(a, b)] = min(d[(a, b)], c)length, frm, to = [], [], []for (a, b), c in d.items():length.append(c)frm.append(a)to.append(b)matr = csr_matrix((length, (frm, to)), shape=(compress_N, compress_N))T = minimum_spanning_tree(matr)ans -= int(T.sum())print(ans)