mst.append(edge)
return mst
# Misol graf uchun bo'ylar
edges = [
(0, 1, 4), (0, 7, 8), (1, 2, 8), (1, 7, 11),
(2, 3, 7), (2, 5, 4), (2, 8, 2), (3, 4, 9),
(3, 5, 14), (4, 5, 10), (5, 6, 2), (6, 7, 1),
(6, 8, 6), (7, 8, 7)
]
n = 9 # Tugmachalar soni
mst = kruskal(edges, n)
print("Eng arzon tayanch daraxt bo'ylari:")
for edge in mst:
print(edge)
4. Algoritmni To’g’riligini Tekshirish:
Algoritmda ishlatilgan klaslar va funksiyalar to'g'ri ishlashini tekshirish uchun grafning
eng arzon tayanch daraxtini chiqaradi.