传送门
裸的最小生成树。
kruskal水过。
var
a,b,c:array [0..100005] of longint;
f:array [0..505] of longint;
n,m,i,x,y,s,max:longint;
procedure kp(l,r:longint);
var i,j,m,t:longint;
begin
i:=l; j:=r; m:=c[(l+r) div 2];
while i<=j do begin
while c[i]<m do inc(i);
while c[j]>m do dec(j);
if i<=j then begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
t:=b[i]; b[i]:=b[j]; b[j]:=t;
t:=c[i]; c[i]:=c[j]; c[j]:=t;
inc(i); dec(j);
end; end;
if l<j then kp(l,j);
if i<r then kp(i,r);
end;
function get(x:longint):longint;
begin
if x=f[x] then exit(x);
f[x]:=get(f[x]);
exit(f[x]);
end;
begin
read(n,m);
for i:=1 to m do read(a[i],b[i],c[i]);
kp(1,m);
s:=0; max:=0;
for i:=1 to n do f[i]:=i;
for i:=1 to m do begin
x:=get(a[i]); y:=get(b[i]);
if (x<>y) then begin inc(s); max:=c[i]; f[x]:=y; end;
end;
write(s,' ',max);
end.