diff --git a/LibreOJ/123/123.cpp b/LibreOJ/123/123.cpp new file mode 100644 index 00000000..6fb9ff9b --- /dev/null +++ b/LibreOJ/123/123.cpp @@ -0,0 +1,40 @@ +#include + +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; +} diff --git a/LibreOJ/123/data/mst1.ans b/LibreOJ/123/data/mst1.ans new file mode 100644 index 00000000..804fcc90 --- /dev/null +++ b/LibreOJ/123/data/mst1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa +size 2 diff --git a/LibreOJ/123/data/mst1.in b/LibreOJ/123/data/mst1.in new file mode 100644 index 00000000..b635b29a --- /dev/null +++ b/LibreOJ/123/data/mst1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4a8ae8e74ddfb896a256de4e3099911dcaa6a9302591713898069b0bcd6e3d7 +size 4 diff --git a/LibreOJ/123/data/mst10.ans b/LibreOJ/123/data/mst10.ans new file mode 100644 index 00000000..fed4a87b --- /dev/null +++ b/LibreOJ/123/data/mst10.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de56c3d81cb3919ee55860f71c4626553d4815ebcb81b3cbdbf002783d0e5ee0 +size 15 diff --git a/LibreOJ/123/data/mst10.in b/LibreOJ/123/data/mst10.in new file mode 100644 index 00000000..f69fef33 --- /dev/null +++ b/LibreOJ/123/data/mst10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a2d34d87cf4d297b48d7012e98d4784497e925041661c1ee2f40b1b64b25cdf +size 11367060 diff --git a/LibreOJ/123/data/mst2.ans b/LibreOJ/123/data/mst2.ans new file mode 100644 index 00000000..804fcc90 --- /dev/null +++ b/LibreOJ/123/data/mst2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa +size 2 diff --git a/LibreOJ/123/data/mst2.in b/LibreOJ/123/data/mst2.in new file mode 100644 index 00000000..50a2535d --- /dev/null +++ b/LibreOJ/123/data/mst2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ec7341d9e65006f144101bcc994c9d44e2a5d81e9d5b60988af168eab6b0494 +size 6922412 diff --git a/LibreOJ/123/data/mst3.ans b/LibreOJ/123/data/mst3.ans new file mode 100644 index 00000000..55e460fe --- /dev/null +++ b/LibreOJ/123/data/mst3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63c191b39e6810f91d2eb7bd05a27eb4e51926fb7d8f19769f3ff64eb6b5e423 +size 13 diff --git a/LibreOJ/123/data/mst3.in b/LibreOJ/123/data/mst3.in new file mode 100644 index 00000000..cbda1aaa --- /dev/null +++ b/LibreOJ/123/data/mst3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:089fac30b0579c7c3e9a3beab1ebfcf12ac099ba3c9bc7c6ac9a26229dd2cc1e +size 19424 diff --git a/LibreOJ/123/data/mst4.ans b/LibreOJ/123/data/mst4.ans new file mode 100644 index 00000000..ef3055f9 --- /dev/null +++ b/LibreOJ/123/data/mst4.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62b80bc11203974629a142fb3a0b0d6d13b6dd638085fd6bd7e525343dc5becc +size 11 diff --git a/LibreOJ/123/data/mst4.in b/LibreOJ/123/data/mst4.in new file mode 100644 index 00000000..eccbe8d6 --- /dev/null +++ b/LibreOJ/123/data/mst4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3788933515b148df3536ea61562ce00fda17bb5b63b9b1020aa2f9b8f8af634f +size 9264617 diff --git a/LibreOJ/123/data/mst5.ans b/LibreOJ/123/data/mst5.ans new file mode 100644 index 00000000..c66c40de --- /dev/null +++ b/LibreOJ/123/data/mst5.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:44a5cb84e7730ef9ce8f76f92220ee8beab9c5e39818932a4fe9afe5548e3c27 +size 12 diff --git a/LibreOJ/123/data/mst5.in b/LibreOJ/123/data/mst5.in new file mode 100644 index 00000000..bec55918 --- /dev/null +++ b/LibreOJ/123/data/mst5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28e8e82f381f244f464af35433cac02572867ed694a847029718563348590fe8 +size 9690815 diff --git a/LibreOJ/123/data/mst6.ans b/LibreOJ/123/data/mst6.ans new file mode 100644 index 00000000..248d2102 --- /dev/null +++ b/LibreOJ/123/data/mst6.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b150da4dd3838c338d32906bdce01ac7b533955fbca08f9e409f6eef9b13ca1 +size 15 diff --git a/LibreOJ/123/data/mst6.in b/LibreOJ/123/data/mst6.in new file mode 100644 index 00000000..0cd77093 --- /dev/null +++ b/LibreOJ/123/data/mst6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f570a1c3b71530daa3cb6514d7b84ea167e807179e09a1738130856e32056719 +size 5405414 diff --git a/LibreOJ/123/data/mst7.ans b/LibreOJ/123/data/mst7.ans new file mode 100644 index 00000000..f3175fdb --- /dev/null +++ b/LibreOJ/123/data/mst7.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8cecfaa858b4bbd39b06fecdb97f4a4156fd8221b3f72450946d7cc1b963e11b +size 15 diff --git a/LibreOJ/123/data/mst7.in b/LibreOJ/123/data/mst7.in new file mode 100644 index 00000000..d1da3882 --- /dev/null +++ b/LibreOJ/123/data/mst7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bdd097f7d35a6e35e2edd41ed6447ff02af81eece7728561ebae676a07086bb8 +size 5404830 diff --git a/LibreOJ/123/data/mst8.ans b/LibreOJ/123/data/mst8.ans new file mode 100644 index 00000000..f76cfdd4 --- /dev/null +++ b/LibreOJ/123/data/mst8.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e48d3af92df930ac0b3e99f8645aed517f29950d8235f0eba3045154603c2f55 +size 15 diff --git a/LibreOJ/123/data/mst8.in b/LibreOJ/123/data/mst8.in new file mode 100644 index 00000000..c9d5ac72 --- /dev/null +++ b/LibreOJ/123/data/mst8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9d71eb1f28d539eac96e1874772ed6e4838051640090fb227299356b29c2a00 +size 4546196 diff --git a/LibreOJ/123/data/mst9.ans b/LibreOJ/123/data/mst9.ans new file mode 100644 index 00000000..bd7fcfdd --- /dev/null +++ b/LibreOJ/123/data/mst9.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3607491c5f659ae51bc310b356aa0398233159e4770427083b4fc4719e1f8635 +size 15 diff --git a/LibreOJ/123/data/mst9.in b/LibreOJ/123/data/mst9.in new file mode 100644 index 00000000..ed3c9e93 --- /dev/null +++ b/LibreOJ/123/data/mst9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:526a92bfe637b9832332c62c809f7eaccc77fe83581a57427b8e730e90ab46b8 +size 11367107