0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 17:16:26 +00:00

#123. 最小生成树

https://loj.ac/s/1316948
This commit is contained in:
Baoshuo Ren 2021-12-05 11:24:00 +08:00
parent d130e48f04
commit de94a09b9b
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
21 changed files with 100 additions and 0 deletions

40
LibreOJ/123/123.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int n, m, fa[500005];
long long ans;
struct node {
int u, v, w;
bool operator<(const node x) const {
return w < x.w;
}
} g[500005];
int find(int x) {
return fa[x] = fa[x] != x ? find(fa[x]) : fa[x];
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> g[i].u >> g[i].v >> g[i].w;
}
std::sort(g, g + m);
for (int i = 1; i <= n; i++) {
fa[i] = i;
}
for (int i = 0; i < m; i++) {
g[i].u = find(g[i].u);
g[i].v = find(g[i].v);
if (g[i].u != g[i].v) {
fa[g[i].u] = g[i].v;
ans += g[i].w;
}
}
cout << ans << endl;
return 0;
}

BIN
LibreOJ/123/data/mst1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/123/data/mst9.in (Stored with Git LFS) Normal file

Binary file not shown.