.........................................................................................................................................................................................................
简单题。
.........................................................................................................................................................................................................
#include<stdio.h>
#include<algorithm>using namespace std;
typedef struct node
{
int a,b;
int c;
int d;
}edge;
edge e[5000];
int father[105];
bool cmp(edge o1,edge o2)
{
if(o1.c<o2.c)
{
return 1;
}
return 0;
}
int Find_Set(int x)
{
return x!=father[x]?father[x]=Find_Set(father[x]):x;
}
int kruskal(int n)
{
int sum=0;
int i,x,y;
for(i=0;i<n;i++)
{
x=e[i].a;
y=e[i].b;
x=Find_Set(x);
y=Find_Set(y);
if(x!=y)
{
father[x]=y;
sum+=e[i].c;
}
}
return sum;
}
int main()
{
int n,i,j;
int sum;
while(scanf("%d",&n)!=EOF&&n)
{
for(i=0;i<n*(n-1)/2;i++)
{
scanf("%d%d%d%d",&e[i].a,&e[i].b,&e[i].c,&e[i].d);
if(e[i].d==1)
e[i].c=0;
}
for(i=0;i<=n;i++)
{
father[i]=i;
}
sort(e,e+n*(n-1)/2,cmp);
sum=kruskal(n*(n-1)/2);
printf("%d\n",sum);
}
return 0;
}