var fa:array[1..500]of longint; e:array[1..250000,1..3]of longint; bo,bb:array[1..250000]of boolean; tt:array[1..3]of longint; ans1,ans2,te:longint; i,j,x,y,fx,fy,n,m:longint; procedure qsort(l,r:longint); var i,j,mid:longint; begin i:=l;j:=r;mid:=e[(i+j) div 2,3]; repeat while (e[i,3]<mid)and(i<r) do inc(i); while (e[j,3]>mid)and(j>l) do dec(j); if i<=j then begin tt:=e[i];e[i]:=e[j];e[j]:=tt; inc(i);dec(j); end; until i>j; if l>j then qsort(l,j); if i<r then qsort(i,r); end; function getfather(x:longint):longint; begin if fa[x]=0 then exit(x) else begin getfather:=getfather(fa[x]); fa[x]:=getfather; end; end; procedure main2; var tot,i,x,y,j,fx,fy:longint; begin tot:=0; fillchar(fa,sizeof(fa),0); te:=0; for i:=1 to m do if bb[i]=false then begin if te=n-1 then break; x:=e[i,1];y:=e[i,2]; fx:=getfather(x); fy:=getfather(y); if fx=fy then continue else begin fa[fy]:=fx;inc(te); tot:=tot+e[i,3]; end; end; if te=n-1 then if tot<ans2 then ans2:=tot; end; begin assign(input,'p1070.in');reset(input); assign(output,'p1070.out');rewrite(output); readln(n,m); for i:=1 to m do readln(e[i,1],e[i,2],e[i,3]); qsort(1,m); for i:=1 to m do begin if te=n-1 then break; x:=e[i,1];y:=e[i,2]; fx:=getfather(x); fy:=getfather(y); if fx=fy then continue else begin fa[fy]:=fx; inc(te); ans1:=ans1+e[i,3]; bo[i]:=true; end; end; ans2:=999999999; for i:=1 to m do if bo[i] then begin bb[i]:=true; main2; bb[i]:=false; end; writeln(ans1); writeln(ans2); close(input);close(output); end. 只能过9个。 第一个点不知道什么诡异的点。