Exercises
Two properties of the minimum spanning tree:
1. The number of sides equal to the edge must be.
2. When all edges of the edge are finished, the connectivity of the graphs is the same.
Prove:
1. The number of edges equal to each other is not the same as the minimum spanning tree.
2, assuming that each method of the edge of the right to the W connectivity is different, then assume that I and J side is not selected at the same time, then we can be in a scheme to add I-Edge (or J-side), so that the connectivity enhancement, and later more expensive side with less, so with this is the minimum spanning tree contradiction. Therefore, the proposition is to be proven.
Code: I do not know why, the following program has a bug, when to come back a off ...
1 typenode1=Record2 X,y,w:longint;3 End;4Node2=Record5 L,r,v:longint;6 End;7 varE:Array[0.. -] ofNode1;8A:Array[0.. -] ofNode2;9 I,n,m,ans,sum,xx,yy,cnt,tot,j:longint;TenHatArray[0.. -] ofLongint; One functionFind (X:longint): Longint; A begin - ifFa[x]<>x Thenfa[x]:=find (Fa[x]); - exit (Fa[x]); the End; - procedureqsort (h,l:longint); - varI,j,m:longint; - Tmp:node1; + begin -i:=h;j:=l;m:=e[(I+J) >>1].W; + Repeat A whileE[i].w<m DoInc (i); at whileE[j].w>m DoDec (j); - ifI<=j Then - begin -tmp:=e[i];e[i]:=e[j];e[j]:=tmp; - Inc (I);d EC (j); - End; in untilI>J; - ifI<l Thenqsort (i,l); to ifJ>h Thenqsort (h,j); + End; - procedureInit; the begin * readln (n,m); $ fori:=1 toM Do withE[i] Doreadln (x,y,w);Panax NotoginsengQsort1, m); -cnt:=0; tot:=0; the fori:=1 toN Dofa[i]:=i; + fori:=1 toM Do A begin the ife[i].w<>e[i-1].w Then + begin -a[cnt].r:=i-1; $ Inc (CNT); $a[cnt].l:=i; - End; -Xx:=find (e[i].x); yy:=find (E[I].Y); the ifXx<>yy Then - beginWuyifa[xx]:=yy; the Inc (A[CNT].V); - Inc (TOT); Wu End; - End; Abouta[cnt].r:=m; $ iftot<n-1 Then beginWriteln (0); halt;End; - End; - procedureDFS (x,now,k:longint); - varXx,yy:longint; A begin + ifnow=a[x].r+1 Then the begin - ifK=a[x].v ThenInc (SUM); $ exit; the End; theXx:=find (e[now].x); yy:=find (E[NOW].Y); the ifXx<>yy Then the begin -fa[xx]:=yy; inDFS (x,now+1, K +1); thefa[xx]:=xx;fa[yy]:=yy; the End; AboutDFS (x,now+1, k); the End; the proceduremain; the begin + fori:=1 toN Dofa[i]:=i; -ans:=1; the fori:=1 toCnt DoBayi begin thesum:=0; theDFS (I,A[I].L,0); -ans:= (Ans*sum)MoD 31011; - forJ:=a[i].l toA[i].r Do the begin theXx:=find (e[j].x); yy:=find (E[J].Y); the ifXx<>yy Thenfa[xx]:=yy; the End; - End; the writeln (ans); the End; the begin94 Init; the main; the End.
View Code