这题要把给的字符串变成边的权值
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
using namespace std; #define sf scanf
#define pf printf
#define debug printf("!\n")
#define blank printf("\n")
#define mem(a,b) memset(a,b,sizeof(a)) const int MaxN = ;
const int INF = <<; int p[MaxN]; char str[][]; int w[MaxN*MaxN],r[MaxN*MaxN],u[MaxN*MaxN],v[MaxN*MaxN]; int m,n; int find(int x){return p[x]==x?x:p[x]=find(p[x]);} int cmp(const int a,const int b)
{
return w[a]<w[b];
} int kruskal()
{
int ans = ,i; for(i = ;i<n;i++) p[i] = i;
for(i = ;i<m;i++) r[i] = i; sort(r,r+m,cmp); for(i = ;i<m;i++)
{
int e = r[i];
int x = find(u[e]);
int y = find(v[e]);
if(x!=y)
{
ans+=w[e];p[x] = y;
}
}
return ans;
} int weight(int i,int j)
{
int w = ,k;
for(k = ;k<;k++)
if(str[i][k]!=str[j][k])
w++;
return w;
} int main()
{
int i,j;
while(~sf("%d",&n),n)
{
m = ;
mem(u,);
mem(v,);
mem(w,); for(i = ;i<n;i++)
{
sf("%s",str[i]);
} for(i = ;i<n;i++)
{
for(j=i+;j<n;j++)
{
int tmp = weight(i,j);
if(tmp==)
break;
u[m] = i;
v[m] = j;
w[m++] = tmp;
}
}
int ans = kruskal();
pf("The highest possible quality is 1/%d.\n",ans); } return ;
}