本题还没有AC。TLE了。。。。先贴上TLE代码:
/*
* 3371_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 = 600;
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 t;
scanf("%d",&t);
while(t--){
memset(father,0,sizeof(father));
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
int i;
int count = 0;
for(i = 0 ; i < m ; ++i){
scanf("%d%d%d",&e[count].begin,&e[count].end,&e[count].weight);
count++;
}
for(i = 0 ; i < k ; ++i){
int tt;
scanf("%d",&tt);
int f[tt];
int j;
for(j = 0 ; j < tt ; ++j){
scanf("%d",&f[j]);
}
for(j = 1 ; j < tt ; ++j){
e[count].begin= f[j-1];
e[count].end = f[j];
e[count].weight = 0;
count++;
}
}
sort(e , e + count , compare);
int sum = kruscal(count);
printf("%d\n",sum);
}
}