結果
問題 |
No.748 yuki国のお財布事情
|
ユーザー |
![]() |
提出日時 | 2018-12-29 17:29:56 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,370 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 57,344 KB |
最終ジャッジ日時 | 2024-10-01 19:42:03 |
合計ジャッジ時間 | 18,843 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 9 WA * 17 |
ソースコード
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)