1)以前的题会直接给村庄编号以及村庄距离。而这道题，这是给出村庄的距离矩阵。村庄的编号信息蕴含在

``````for(i = 1 ; i <= n ; ++i){
for(j = i + 1 ; j <= n ; ++j){
e[count].begin = i;
e[count].end = j;
e[count].weight = map[i][j];
count++;
}
}``````

2)点的起始编号与变得起始编号没有必然的联系。即点可以从1开始计数，而边则从0开始计数。

``````for( i = 1 ; i < maxn ; ++i){
father[i] = i;
}

for( i = 0 ; i < count ; ++i){
int fx = find(e[i].begin);
int fy = find(e[i].end);

if(fx != fy){
father[fx] = fy;
sum += e[i].weight;
}
}``````

3)已修的路，令weight为0即可。

``````/*
* 1102_1.cpp
*
*  Created on: 2013年8月26日
*      Author: Administrator
*/

#include <iostream>

using namespace std;

struct edge{
int begin;
int end;
int weight;
};

const int maxn = 6000;
int father[maxn];
edge e[maxn*maxn];

int find(int x){
if( x == father[x]){
return x;
}

father[x] = find(father[x]);
return father[x];
}

int kruscal(int count){
int i;
int sum = 0;

for( i = 1 ; i < maxn ; ++i){
father[i] = i;
}

for( i = 0 ; i < count ; ++i){
int fx = find(e[i].begin);
int fy = find(e[i].end);

if(fx != fy){
father[fx] = fy;
sum += e[i].weight;
}
}

return sum;
}

bool compare(const edge& a , const edge& b){
return a.weight < b.weight;
}

int main(){
int n;
while(scanf("%d",&n)!=EOF){
int i,j;
int map[n+1][n+1];
for( i = 1 ; i <= n ; ++i){
for( j =  1 ; j <= n ; ++j){
scanf("%d",&map[i][j]);
}
}
int q;
scanf("%d",&q);
for( i = 1 ; i <= q ; ++i){
int a ,b;
scanf("%d%d",&a,&b);
map[a][b] = 0;
}
int count = 0;
for(i = 1 ; i <= n ; ++i){
for(j = i + 1 ; j <= n ; ++j){
e[count].begin = i;
e[count].end = j;
e[count].weight = map[i][j];
count++;
}
}

sort(e, e + count , compare);

int sum = kruscal(count);

printf("%d\n",sum);

}
}``````