Minimum spanning tree Kruskal

int cmp(const int i, const int j)
{
Return w[i] < w[j];
}//Indirect sort function
Int find(int x)
{
Return p[x] == x? x:p[x] = find(p[x]);
}//and find the find
Int Kruskal()
{
Int ans = 0;
For(int i=0; i<n; i++)
p[i] = i; / / initialize and check
For(int i=0; i<m; i++)
r[i] = i; / / initialization side number
Sort(r, r+m, cmp);//sort the edges
For(int i=0; i<m; i++)
{
Int e = r[i];
Int x = find(u[e]);
Int y = find(v[e]);
/ / Find out the current set number of the two endpoints
If(x!=y)
{
Ans += w[e];
p[x] = y;
}//If in different collections, merge
}
Return ans;
}

uva1395

#include <bits/stdc++.h>
Using namespace std;
Int p[200]; / / used to save the parent node of each vertex
Struct node//edge element
{
    Int from, to, weight;
}edge[10000];
Bool cmp(node ​​a, node b)
{
    Return a.weight < b.weight;
}
Int Find(int x)// find the root node of x
{
 Return x == p[x]?x:p[x] = Find(p[x]);
}

Int main()
{
    Int n, m; / / n is the number of vertices m is the number of sides
    While(scanf("%d%d", &n, &m)&&(n||m))
    {
        Int ans = -1;
        For(int i=0; i<m; i++)
        {
            Scanf("%d%d%d", &edge[i].from, &edge[i].to, &edge[i].weight);
        }
        Sort(edge, edge+m, cmp);
        For(int i=0; i<m; i++)// Note the double loop here, the outer loop is used to find the left starting point
        {
            For(int k=0; k<=n; k++)
            p[k] = k;// assign initial value, where each point is its own MST
            Int num = 0;
        For(int j=i; j<m; j++)// inner loop is used to find the right end
        {
            Node e = edge[j];
            Int x = Find(e.from);
            Int y = Find(e.to);
            If(x!=y)
            {
                p[x] = y;
                Num++;
                If(num==n-1)// found a MST that satisfies the condition
                {
                    If(ans == -1)
                        Ans = edge[j].weight-edge[i].weight;
                    Else
                        Ans = min(ans, edge[j].weight-edge[i].weight);
                }
            }
        }
        }
        Printf("%d\n", ans);
    }
    Return 0;
}
/*
4 5
1 2 3
1 3 5
1 4 6
2 4 6
3 4 7
4 6
1 2 10
1 3 100
1 4 90
2 3 20
2 4 80
3 4 40
twenty one
1 2 1
3 0
3 1
1 2 1
3 3
1 2 2
2 3 5
1 3 6
5 10
1 2 110
1 3 120
1 4 130
1 5 120
2 3 110
2 4 120
2 5 130
3 4 120
3 5 110
4 5 120
5 10
1 2 9384
1 3 887
1 4 2778
1 5 6916
2 3 7794
2 4 8336
2 5 5387
3 4 493
3 5 6650
4 5 1422
5 8
1 2 1
2 3 100
3 4 100
4 5 100
1 5 50
2 5 50
3 5 50
4 1 150
0 0
*/