Write a program that implements Kruskal's algorithm to generate minimum cost spanning tree.

#include <stdio.h>
#include <conio.h>
#define Infinity 9999
#define Max_Vertex 10
void main() {
    int cost[Max_Vertex][Max_Vertex], n, edg;
    int parent[Max_Vertex] = {0};
    int i, j;
    clrscr();
    printf("ENTER THE NUMBER OF VERTICES\n");
    scanf("%d", &n);
    printf("ENTER THE NUMBER OF EDGES\n");
    scanf("%d", &edg);
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
            cost[i][j] = Infinity;
        }
    }
    printf("ENTER THE Edge (u,v) and COST\n");
    int cst;
    for (int z = 1; z <= edg; z++) {
        scanf("%d%d%d", &i, &j, &cst);
        cost[i][j] = cost[j][i] = cst;
    }
    int totEdgeCount = 1;
    int u, v, tempU, tempV, mc = 0;
    while (totEdgeCount < n) {
        int min = Infinity;
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= n; j++) {
                if (cost[i][j] < min) {
                    min = cost[i][j];
                    tempU = u = i;
                    tempV = v = j;
                }
            }
        }
        while (parent[tempU])
            tempU = parent[tempU];
        while (parent[tempV])
            tempV = parent[tempV];
        if (tempV != tempU) {
            printf("%d edge (%d,%d) = %d\n", totEdgeCount++, u, v, min);
            mc = mc + min;
            parent[tempV] = u;
        }
        cost[u][v] = cost[v][u] = Infinity;
    }
    printf("\nMINIMUM COST OF SPANNING TREE IS %d\n", mc);
    getch();
}