結果

問題 No.748 yuki国のお財布事情
ユーザー H3PO4H3PO4
提出日時 2021-01-05 09:43:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,588 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 83,740 KB
最終ジャッジ日時 2024-04-23 16:04:26
合計ジャッジ時間 33,284 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 848 ms
56,824 KB
testcase_01 AC 822 ms
56,692 KB
testcase_02 AC 820 ms
57,080 KB
testcase_03 AC 837 ms
56,700 KB
testcase_04 AC 833 ms
56,568 KB
testcase_05 AC 829 ms
56,828 KB
testcase_06 AC 822 ms
56,832 KB
testcase_07 AC 830 ms
56,948 KB
testcase_08 AC 825 ms
56,820 KB
testcase_09 AC 825 ms
56,824 KB
testcase_10 AC 826 ms
56,820 KB
testcase_11 AC 829 ms
56,832 KB
testcase_12 AC 837 ms
56,696 KB
testcase_13 AC 890 ms
58,012 KB
testcase_14 AC 937 ms
58,832 KB
testcase_15 AC 891 ms
58,764 KB
testcase_16 AC 1,009 ms
62,080 KB
testcase_17 AC 1,471 ms
76,208 KB
testcase_18 AC 1,452 ms
74,740 KB
testcase_19 AC 1,331 ms
75,256 KB
testcase_20 AC 1,294 ms
72,948 KB
testcase_21 AC 1,459 ms
74,100 KB
testcase_22 AC 843 ms
55,796 KB
testcase_23 AC 841 ms
56,180 KB
testcase_24 AC 846 ms
56,700 KB
testcase_25 AC 1,552 ms
80,548 KB
testcase_26 AC 1,588 ms
83,488 KB
testcase_27 AC 1,559 ms
83,740 KB
testcase_28 AC 1,182 ms
67,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict
import numpy as np
from scipy.sparse.csgraph import connected_components, minimum_spanning_tree
from scipy.sparse import csr_matrix

input = sys.stdin.buffer.readline
MAX = 10 ** 10

N, M, K = map(int, input().split())
if not M: print(0);exit()

ABC = np.array([tuple(map(int, input().split())) for _ in range(M)], dtype=np.int64)
ABC[:, :2] -= 1

ans = 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 = N

d = defaultdict(lambda: MAX)
for a, b, c in ABC:
    if a == b:
        continue
    if a > b: a, b = b, a
    d[(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)
0