結果

問題 No.748 yuki国のお財布事情
ユーザー htkbhtkb
提出日時 2018-10-19 22:18:21
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 555 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 29,912 KB
最終ジャッジ日時 2023-08-12 01:18:34
合計ジャッジ時間 6,511 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,372 KB
testcase_01 AC 17 ms
8,284 KB
testcase_02 AC 18 ms
8,264 KB
testcase_03 AC 17 ms
8,412 KB
testcase_04 AC 17 ms
8,300 KB
testcase_05 AC 16 ms
8,372 KB
testcase_06 AC 16 ms
8,368 KB
testcase_07 AC 17 ms
8,316 KB
testcase_08 AC 17 ms
8,384 KB
testcase_09 AC 17 ms
8,308 KB
testcase_10 AC 16 ms
8,380 KB
testcase_11 AC 17 ms
8,216 KB
testcase_12 AC 17 ms
8,312 KB
testcase_13 AC 57 ms
11,264 KB
testcase_14 AC 103 ms
12,984 KB
testcase_15 AC 69 ms
11,540 KB
testcase_16 AC 188 ms
16,736 KB
testcase_17 AC 418 ms
27,744 KB
testcase_18 AC 489 ms
29,036 KB
testcase_19 AC 555 ms
29,560 KB
testcase_20 AC 470 ms
27,172 KB
testcase_21 AC 480 ms
28,516 KB
testcase_22 AC 16 ms
8,232 KB
testcase_23 AC 17 ms
8,400 KB
testcase_24 AC 17 ms
8,340 KB
testcase_25 AC 330 ms
25,260 KB
testcase_26 AC 498 ms
29,912 KB
testcase_27 AC 491 ms
29,868 KB
testcase_28 AC 341 ms
22,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def kruskal(v_count: int, edges: list) -> int:
    """
    :param v_count: 頂点数
    :param edges: [(weight, from, to), ... ]
    """
    from itertools import islice
    tree = [-1]*v_count

    def get_root(x) -> int:
        if tree[x] < 0:
            return x
        tree[x] = get_root(tree[x])
        return tree[x]

    def unite(a) -> bool:
        x, y = get_root(a[1]), get_root(a[2])
        if x != y:
            big, small = (x, y) if tree[x] < tree[y] else (y, x)
            tree[big] += tree[small]
            tree[small] = big
        return x != y

    cost = 0
    for w, _s, _t in islice(filter(unite, sorted(edges)), v_count-1):
        cost += w
    return cost


if __name__ == "__main__":
    import sys
    N, M, K = map(int, input().split())
    edges = [[c, a-1, b-1] for _ in [0]*M for a, b, c in (map(int, sys.stdin.readline().split()),)]
    total = sum(v[0] for v in edges)
    cost = 0
    for e in map(int, sys.stdin):
        cost += edges[e-1][0]
        edges[e-1][0] = 0

    print(total - (kruskal(N, edges) + cost))
0