0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 06:38:48 +00:00

P2330 [SCOI2005]繁忙的都市

R53170821
This commit is contained in:
Baoshuo Ren 2021-07-15 08:58:55 +08:00 committed by Baoshuo Ren
parent 605d9549b3
commit 57ade6ea99
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,37 @@
#include <bits/stdc++.h>
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;
}