結果

問題 No.748 yuki国のお財布事情
ユーザー htkbhtkb
提出日時 2018-10-19 22:18:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 611 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 32,088 KB
最終ジャッジ日時 2024-04-29 16:07:40
合計ジャッジ時間 7,063 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 33 ms
10,624 KB
testcase_03 AC 32 ms
10,624 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 30 ms
10,624 KB
testcase_07 AC 31 ms
10,624 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 31 ms
10,624 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 30 ms
10,624 KB
testcase_12 AC 30 ms
10,624 KB
testcase_13 AC 76 ms
13,568 KB
testcase_14 AC 128 ms
15,232 KB
testcase_15 AC 89 ms
14,208 KB
testcase_16 AC 221 ms
19,212 KB
testcase_17 AC 482 ms
30,160 KB
testcase_18 AC 554 ms
31,628 KB
testcase_19 AC 611 ms
32,040 KB
testcase_20 AC 545 ms
29,608 KB
testcase_21 AC 561 ms
31,156 KB
testcase_22 AC 31 ms
10,624 KB
testcase_23 AC 31 ms
10,752 KB
testcase_24 AC 31 ms
10,752 KB
testcase_25 AC 390 ms
27,720 KB
testcase_26 AC 569 ms
32,088 KB
testcase_27 AC 552 ms
32,064 KB
testcase_28 AC 398 ms
24,992 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