| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 6497 |
| 문제명 | 전력난 |
| 레벨 | 골드 4 |
| 분류 |
최소 신장 트리 |
| 시간복잡도 | O(T*ElogV) |
| 인풋사이즈 | T<=?, V<=200,000, E<=200,000 |
| 사용한 언어 | Python |
| 제출기록 | 95340KB / 1380ms |
| 최고기록 | 1172ms |
| 해결날짜 | 2022/09/29 |
| 태그 | |
"""Solution code for "BOJ 6497. 전력난".
- Problem link: https://www.acmicpc.net/problem/6497
- Solution link: http://www.teferi.net/ps/problems/boj/6497
Tags: [Minimum spanning tree]
"""
import sys
from teflib import graph as tgraph
def main():
while (line := sys.stdin.readline().rstrip()) != '0 0':
m, n = [int(x) for x in line.split()]
edges = [
[int(x) for x in sys.stdin.readline().split()] for _ in range(n)
]
total_cost = sum(z for x, y, z in edges)
mst_edges = tgraph.minimum_spanning_tree(edges, m)
mst_cost = sum(z for x, y, z in mst_edges)
print(total_cost - mst_cost)
if __name__ == '__main__':
main()