mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-30 17:16:26 +00:00
parent
d130e48f04
commit
de94a09b9b
40
LibreOJ/123/123.cpp
Normal file
40
LibreOJ/123/123.cpp
Normal 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
BIN
LibreOJ/123/data/mst9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user