結果

問題 No.748 yuki国のお財布事情
ユーザー H3PO4H3PO4
提出日時 2021-01-05 09:41:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,090 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 84,372 KB
最終ジャッジ日時 2024-04-23 16:01:54
合計ジャッジ時間 39,962 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,044 ms
55,160 KB
testcase_01 AC 963 ms
54,520 KB
testcase_02 AC 940 ms
54,904 KB
testcase_03 AC 950 ms
54,648 KB
testcase_04 AC 948 ms
54,904 KB
testcase_05 AC 939 ms
55,288 KB
testcase_06 AC 948 ms
54,916 KB
testcase_07 AC 943 ms
54,908 KB
testcase_08 AC 950 ms
55,032 KB
testcase_09 AC 940 ms
54,788 KB
testcase_10 AC 945 ms
55,160 KB
testcase_11 AC 954 ms
54,772 KB
testcase_12 AC 940 ms
54,908 KB
testcase_13 AC 1,016 ms
57,720 KB
testcase_14 AC 1,063 ms
57,884 KB
testcase_15 AC 1,038 ms
57,120 KB
testcase_16 AC 1,162 ms
61,440 KB
testcase_17 AC 1,840 ms
77,108 KB
testcase_18 AC 1,546 ms
73,852 KB
testcase_19 AC 1,524 ms
75,068 KB
testcase_20 AC 1,454 ms
71,288 KB
testcase_21 AC 1,656 ms
73,472 KB
testcase_22 RE -
testcase_23 AC 949 ms
54,264 KB
testcase_24 AC 939 ms
54,392 KB
testcase_25 AC 1,714 ms
80,472 KB
testcase_26 AC 1,737 ms
84,372 KB
testcase_27 AC 1,745 ms
83,572 KB
testcase_28 AC 1,316 ms
67,452 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())
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