Estou dando uma estudada em grafos implementados em c e me deparei com um código que estou com duvida para entender, Alguém poderia me ajudar comentando as operações que estão sendo realizadas nele?
#include <stdio.h>
typedef struct TipoAresta{
int V1, V2;
int Peso;
}TipoAresta;
void QuickSort (TipoAresta *v, int inicio, int fim)
{
if(inicio<fim)
{
int i=inicio, j; // j = contador
TipoAresta pivo = v[inicio];
for(j=inicio+1; j<=fim; j++)
{
if(v[j].Peso < pivo.Peso)
{
v[i] = v[j];
v[j] = v[i+1];
i++;
}
}
v[i] = pivo;
QuickSort(v, inicio, i-1);
QuickSort(v, i+1, fim);
}
}
int main ()
{
int Num_Arestas, Num_Vertices, SomaA, SomaB;
int i, j;
while (scanf("%d %d", &Num_Vertices, &Num_Arestas) && Num_Vertices)
{
SomaA = SomaB = 0;
int Conjunto[Num_Vertices+1];
TipoAresta Aresta[Num_Arestas+1];
for(i=0; i<Num_Vertices; i++) Conjunto[i] = i;
for (i = 0; i < Num_Arestas; i++){
scanf("%d %d %d", &Aresta[i].V1, &Aresta[i].V2, &Aresta[i].Peso);
SomaA += Aresta[i].Peso;
}
QuickSort(Aresta, 0, Num_Arestas-1);
for(i=0; i < Num_Arestas; i++){
if(Conjunto[Aresta[i].V1] != Conjunto[Aresta[i].V2]){
SomaB += Aresta[i].Peso; // Só quero a soma dos menores pesos
int aux = Conjunto[Aresta[i].V2];
for(j=0; j < Num_Vertices; j++){
if ( Conjunto[j] == aux )
Conjunto[j] = Conjunto[Aresta[i].V1];
}
}
}
printf("%d\n", SomaA - SomaB);
}
return 0;
}