1 #include <bits/stdc++.h>
2 using namespace std;
3 int pre[100010],n,m,ans=0;
4 struct edge {
5 int a,b,w;
6 }e[100010];
7 int cnt=0;
8 int cmp(const void *i, const void *j) {
9 struct edge *c= (struct edge*) i;
10 struct edge *d= (struct edge*) j;
11 return c->w - d->w;
12 }
13 int getf(int x) {
14 int r=x;
15 while(r!=pre[r]) r=pre[r];
16 int i=x,j;
17 while(i!=r) {
18 j=pre[i];
19 pre[i]=r;
20 i=j;
21 }
22 return r;
23 }
24
25 int main() {
26 scanf("%d%d",&n,&m);
27 for (int i=1;i<=m;++i)
28 scanf("%d %d %d",&e[i].a,&e[i].b,&e[i].w);
29 qsort(e+1,m,sizeof(struct edge),cmp);
30 for (int i=1;i<=300;++i) pre[i]=i;
31 int fa,fb;
32 for (int i=1;i<=m;++i) {
33 fa=getf(e[i].a);
34 fb=getf(e[i].b);
35 if(fa!=fb) {
36 pre[fa]=fb;
37 ans=e[i].w;
38 cnt++;
39 if(cnt==n-1) break;
40 }
41 }
42 printf("%d %d\n",n-1,ans);
43 return 0;
44 }