結果

問題 No.748 yuki国のお財布事情
ユーザー ckawatakckawatak
提出日時 2018-12-29 17:29:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,370 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 57,344 KB
最終ジャッジ日時 2024-04-09 19:31:01
合計ジャッジ時間 17,099 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,136 KB
testcase_01 AC 31 ms
11,264 KB
testcase_02 WA -
testcase_03 AC 34 ms
11,136 KB
testcase_04 AC 33 ms
11,136 KB
testcase_05 AC 32 ms
11,264 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 33 ms
11,264 KB
testcase_23 AC 32 ms
11,264 KB
testcase_24 AC 32 ms
11,136 KB
testcase_25 WA -
testcase_26 AC 1,534 ms
54,272 KB
testcase_27 AC 1,526 ms
54,272 KB
testcase_28 AC 1,181 ms
41,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from queue import PriorityQueue

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

streets = []
for _ in range(N):
    streets.append([])

total_cost = 0    
costs = [0 for _ in range(M)]
for i in range(M):
    a, b, c = list(map(int, input().split(' ')))
    streets[a-1].append((i,b-1,c))
    streets[b-1].append((i,a-1,c))
    costs[i] = c
    total_cost = total_cost + c

kept = []
for _ in range(K):
    e = int(input())
    kept.append(e-1)

included = [0 for _ in range(M)]    
key = [float('inf') for _ in range(N)]
parent = [-1 for _ in range(N)]
mst = [0 for _ in range(N)]

que = PriorityQueue()
que.put((0,0))
key[0] = 0

while not que.empty():
    _,country_a = que.get()

    mst[country_a] = 1
    for street in streets[country_a]:
        i, country_b, cost = street
        if mst[country_b] == 0 and cost < key[country_b]:
            key[country_b] = cost
            que.put((key[country_b],country_b))
            parent[country_b] = country_a

for i in range(1,N):
    for street in streets[i]:
        if street[1] == parent[i]:
            included[street[0]] = 1
            
cost = 0
for i in range(M):
    if included[i] == 1:
        cost = cost + costs[i]

for i in kept:
    included[i] = 1

minimum_cost = 0    
for i in range(M):
    if included[i] == 1:
        minimum_cost = minimum_cost + costs[i]
        
print(total_cost - minimum_cost)
0