文章
60
粉丝
361
获赞
43
访问
524.7k
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node
{
int u;
int v;
int weight;
int state;
}griph[105];
int a[105];
bool compare(node a,node b)
{
if(a.state ==b.state )//同状态返回权值小
return a.weight <b.weight ;
else//不同优先已建
return a.state>b.state;
}
int find(int x)
{
if(x==a[x])return x;
a[x]=find(a[x]);
return a[x];
}
int main()
{
int n;
while(cin>>n)
{
if(n==0)break;
int hang=n*(n-1)/2;
int sum=0,flag=0;
for(int i=1;i<=n;i++)
a[i]=i;
//输入
for(int i=0;i<hang;i++)
{
cin>>griph[i].u>>griph[i].v>>griph[i].weight>>griph[i].state ;
}
sort(griph,griph+hang,compare);
for(int i=0;i<hang;i++)
{
int xi=find(griph[i].u);
int yi=find(griph[i].v);
if(xi!=yi)
{
a[xi]=yi;
if(griph [i].state ==0)//未建
sum+...
登录后发布评论
暂无评论,来抢沙发