結果

問題 No.748 yuki国のお財布事情
ユーザー ckawatakckawatak
提出日時 2018-12-29 22:40:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,020 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 34,908 KB
最終ジャッジ日時 2024-04-10 10:01:46
合計ジャッジ時間 11,170 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
13,312 KB
testcase_01 AC 51 ms
13,312 KB
testcase_02 AC 48 ms
13,312 KB
testcase_03 AC 50 ms
13,312 KB
testcase_04 AC 49 ms
13,184 KB
testcase_05 AC 49 ms
13,312 KB
testcase_06 AC 49 ms
13,312 KB
testcase_07 AC 50 ms
13,312 KB
testcase_08 AC 49 ms
13,312 KB
testcase_09 AC 49 ms
13,312 KB
testcase_10 AC 49 ms
13,184 KB
testcase_11 AC 48 ms
13,184 KB
testcase_12 AC 49 ms
13,312 KB
testcase_13 AC 139 ms
15,488 KB
testcase_14 AC 212 ms
17,280 KB
testcase_15 AC 152 ms
16,000 KB
testcase_16 AC 374 ms
20,992 KB
testcase_17 AC 681 ms
30,208 KB
testcase_18 AC 871 ms
32,684 KB
testcase_19 AC 1,020 ms
34,560 KB
testcase_20 AC 912 ms
32,240 KB
testcase_21 AC 848 ms
33,512 KB
testcase_22 AC 49 ms
13,184 KB
testcase_23 AC 49 ms
13,184 KB
testcase_24 AC 49 ms
13,184 KB
testcase_25 AC 629 ms
26,496 KB
testcase_26 AC 810 ms
34,908 KB
testcase_27 AC 775 ms
34,808 KB
testcase_28 AC 675 ms
27,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

parent = []
rank = []
edges = []

def init(n):
    for i in range(n):
        parent.append(i)
        rank.append(0)

def find(x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent[x])
        return parent[x]
        
def unite(x, y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        parent[x] = y
    else:
        parent[y] = x
        if rank[x] == rank[y]:
            rank[x] = rank[x] + 1

def same(x, y):
    return find(x) == find(y)

def kruskal(e):
    edges.sort()
    cost = 0
    for i in range(e):
        if not same(edges[i][1], edges[i][2]):
            unite(edges[i][1], edges[i][2])
            cost = cost + edges[i][0]
    return cost

N,M,K = list(map(int, input().split(' ')))

a = [0 for _ in range(10**5)]
b = [0 for _ in range(10**5)]
c = [0 for _ in range(10**5)]

for i in range(M):
    a[i], b[i], c[i] = list(map(int, input().split(' ')))
    edges.append((c[i], a[i], b[i]))
cost = sum(c)

init(N+1)
for i in range(K):
    e = int(input())
    e = e - 1
    cost = cost - c[e]
    unite(a[e], b[e])

print(cost - kruskal(M))
0