From 57ade6ea99e802942756c23ab9b8c7f06c9ba3d5 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 15 Jul 2021 08:58:55 +0800 Subject: [PATCH] =?UTF-8?q?P2330=20[SCOI2005]=E7=B9=81=E5=BF=99=E7=9A=84?= =?UTF-8?q?=E9=83=BD=E5=B8=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R53170821 --- Luogu/problem/P2330/P2330.cpp | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Luogu/problem/P2330/P2330.cpp diff --git a/Luogu/problem/P2330/P2330.cpp b/Luogu/problem/P2330/P2330.cpp new file mode 100644 index 00000000..51369b3b --- /dev/null +++ b/Luogu/problem/P2330/P2330.cpp @@ -0,0 +1,37 @@ +#include + +using namespace std; + +struct edge { + int from, to, dis; + + bool operator<(edge b) const { + return dis < b.dis; + } +} e[100005]; + +int n, m, s, maxx, fa[10005]; + +int get(int x) { + if (fa[x] == x) return x; + return fa[x] = get(fa[x]); +} + +int main() { + cin >> n >> m; + for (int i = 0; i < m; i++) { + cin >> e[i].from >> e[i].to >> e[i].dis; + } + for (int i = 0; i < n; i++) { + fa[i] = i; + } + sort(e, e + m); + for (int i = 0; i < m; i++) { + int x = get(e[i].from), y = get(e[i].to); + if (x == y) continue; + fa[x] = y; + maxx = e[i].dis; + } + cout << n - 1 << " " << maxx << endl; + return 0; +}