Include minimum weight edges one by one
edge_count = 0 NEW_LINE while edge_count < V - 1 : NEW_LINE INDENT min = INF NEW_LINE a = - 1 NEW_LINE b = - 1 NEW_LINE for i in range ( V ) : NEW_LINE INDENT for j in range ( V ) : NEW_LINE INDENT if find ( i ) != find ( j ) and cost [ i ] [ j ] < min : NEW_LINE INDENT min = cost [ i ] [ j ] NEW_LINE a = i NEW_LINE b = j NEW_LINE DEDENT DEDENT DEDENT union ( a , b ) NEW_LINE print ( ' Edge ▁ { } : ( { } , ▁ { } ) ▁ cost : { } ' . format ( edge_count , a , b , min ) ) NEW_LINE edge_count += 1 NEW_LINE mincost += min NEW_LINE DEDENT print ( " Minimum ▁ cost = ▁ { } " . format ( mincost ) ) NEW_LINE