1 #include <bits/stdc++.h>
2 using namespace std;
3 struct edge
4 {
5 int u, v, w;
6 bool operator < (const edge &rhs) const
7 {
8 return w < rhs.w;
9 }
10 }e[100005];
11 int fa[305], n, m;
12
13 int getfa(int x)
14 {
15 return fa[x] = x == fa[x] ? x : getfa(fa[x]);
16 }
17
18 int Kruskal()
19 {
20 int u, v, w, cnt = 0;
21 sort(e + 1, e + m + 1);
22 for(int i = 1; i <= m; i++)
23 {
24 u = getfa(e[i].u), v = getfa(e[i].v);
25 if(u != v)
26 {
27 fa[v] = u, w = e[i].w;
28 if(++cnt == n - 1) break;
29 }
30 }
31 return w;
32 }
33
34 int main()
35 {
36 int u, v, w;
37 cin >> n >> m;
38 for(int i = 1; i <= n; i++)
39 fa[i] = i;
40 for(int i = 1; i <= m; i++)
41 {
42 cin >> u >> v >> w;
43 e[i] = (edge){u, v, w};
44 }
45 cout << n - 1 << ‘ ‘ << Kruskal() << endl;
46 return 0;
47 }