|
|
|
@ -51,11 +51,11 @@ const int N = 2010, M = 10010;
|
|
|
|
|
int n, m, p[N];
|
|
|
|
|
|
|
|
|
|
struct Edge {
|
|
|
|
|
int a, b, w;
|
|
|
|
|
int a, b, c;
|
|
|
|
|
bool operator<(const Edge &t) const {
|
|
|
|
|
return w < t.w;
|
|
|
|
|
return c < t.c;
|
|
|
|
|
}
|
|
|
|
|
} e[M];
|
|
|
|
|
} edge[M];
|
|
|
|
|
int el;
|
|
|
|
|
|
|
|
|
|
int find(int x) {
|
|
|
|
@ -78,19 +78,19 @@ int main() {
|
|
|
|
|
p[find(a)] = find(b), res += c;
|
|
|
|
|
else
|
|
|
|
|
// 记录可选边有哪些
|
|
|
|
|
e[el++] = {a, b, c};
|
|
|
|
|
edge[el++] = {a, b, c};
|
|
|
|
|
}
|
|
|
|
|
// 对可选边进行由小到大排序
|
|
|
|
|
sort(e, e + el);
|
|
|
|
|
sort(edge, edge + el);
|
|
|
|
|
|
|
|
|
|
// 枚举每条可选边
|
|
|
|
|
for (int i = 0; i < el; i++) {
|
|
|
|
|
int a = find(e[i].a), b = find(e[i].b), c = e[i].w;
|
|
|
|
|
int a = find(edge[i].a), b = find(edge[i].b), c = edge[i].c;
|
|
|
|
|
if (a != b) p[a] = b, res += c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 输出最短长度
|
|
|
|
|
printf("%d\n", res);
|
|
|
|
|
cout << res << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|