문제
나의 풀이
1. 성공 but 앞에 이론 복습 했기 때문에..
def find_parendt(parent, x):
if parent[x] != x:
parent[x] = find_parendt(parent, parent[x])
return parent[x]
def union_parent(parent, a, b):
a = find_parendt(parent, a)
b = find_parendt(parent, b)
if a < b:
parent[b] = a
else:
parent[a] = b
n, m = map(int, input().split())
parent = list(range(1, n + 1))
edges = []
all = 0
result = 0
for _ in range(m):
a, b, cost = map(int, input().split())
edges.append((cost, a, b))
edges.sort()
for cost, a, b in edges:
all += cost
if find_parendt(parent, a) != find_parendt(parent, b):
union_parent(parent, a, b)
result += cost
print(all - result)