kruskal/and check Set + enumeration
Alas, I'm still too Naive,orz hzwer.
At first I was thinking: the minimum spanning tree to delete an edge, plus an edge is still the smallest spanning tree, then these two edge weights must be equal, but I can also remove two weights of 1 and 3, plus the weights of 2 and 2, not also meet test instructions? In fact, if that's the case ... The minimum spanning tree should be 1 and 2 instead of 1 and 3 or 2 and 2!!!
So? So for a graph, the minimum spanning tree has several sides of the right side, which are fixed! So we can do it again Kruskal find out these edge rights, and the number of times each edge right appears. Then, for each kind of edge right, say appear $v_i$ times, then can replace must be formed ring! And this side right of the choice of the other side of the right to have no effect, I can $2^{v_i}$ enumeration of whether each edge is selected, violence to find out the number of feasible $v_i$ edge, this complexity is not high, because the topic guaranteed here $v_i \leq 10$.
1 /**************************************************************2 problem:10163 User:tunix4 language:c++5 result:accepted6 Time:8 Ms7 memory:1300 KB8 ****************************************************************/9 Ten //Bzoj 1016 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - #definePB Push_back + using namespacestd; AInlineintGetint () { at intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } - Const intn= the, inf=~0u>>2, mod=31011; intypedefLong LongLL; - /******************tamplate*********************/ to intN,m,fa[n]; + structedge{intU,v,w;} e[1010]; - structdata{intL,r,v;} a[1010]; the BOOLCMP (Edge A,edge b) {returna.w<B.W;} * intFind (intx) {returnFa[x]==x?X:find (fa[x]);} $ intsum,ans=1, tot;Panax Notoginseng voidDfsintXintNowintk) { - if(now==a[x].r+1){ the if(K==A[X].V) sum++; + return; A } the intP=find (e[now].u), q=Find (E[NOW].V); + if(p!=q) { -fa[p]=Q; $DFS (x,now+1, K +1); $Fa[p]=p; fa[q]=Q; - } -DFS (x,now+1, k); the } - intMain () {Wuyi #ifndef Online_judge theFreopen ("1016.in","R", stdin); -Freopen ("1016.out","W", stdout); Wu #endif -N=getint (); m=getint (); AboutF (I,1, M) { $E[i].u=getint (); E[i].v=getint (); e[i].w=getint (); - } -Sort (e+1, e+m+1, CMP); - intCnt=0, now=0; AF (I,1, N) fa[i]=i; +F (I,1, M) { the if(i==1|| e[i].w!=e[i-1].W) {a[++cnt].l=i;a[cnt-1].r=i-1;} - intP=find (e[i].u), q=Find (E[I].V); $ if(P!=Q) {fa[p]=q; a[cnt].v++; tot++;} the } theA[cnt].r=m; the if(tot!=n-1) {puts ("0");return 0;} theF (I,1, N) fa[i]=i; -F (I,1, CNT) { insum=0; theDFS (I,A[I].L,0); theans=ans*sum%MOD; About F (J,A[I].L,A[I].R) { the intP=find (e[j].u), q=Find (E[J].V); the if(p!=q) fa[p]=Q; the } + } -printf"%d\n", ans); the return 0;Bayi}
View Code 1016: [JSOI2008] minimum spanning tree count time limit:1 Sec Memory limit:162 MB
submit:3312 solved:1311
[Submit] [Status] [Discuss] Description
A simple, non-weighted graph is now given. You are not satisfied with finding the smallest spanning tree of the graph, but want to know how many different minimum spanning trees are in the graph. (If there is at least one edge in the two smallest spanning trees, the two minimum spanning trees are different). Because the different minimum spanning tree may be many, you only need to output the scheme number to 31011 modulo.
Input
The first line contains two numbers, N and M, where 1<=n<=100; 1<=m<=1000; Represents the number of nodes and sides of the graph. Each node is numbered with an integer of 1~n. The next M-line, each line contains two integers: A, B, C, the weight of the edge between Node A and B is C, where 1<=c<=1,000,000,000. Data guarantees that no self-back and heavy edges are present. Note: An edge with the same weight will not exceed 10 bars.
Output
How many of the different minimum spanning trees are output. You just need to output a number of 31011 modulo.
Sample Input4 6
1 2 1
1 3 1
1 4 1
2 3 2
2 4 1
3 4 1Sample Output8Hintsource [Submit] [Status] [Discuss]
"Bzoj" "1016" "JSOI2008" minimum spanning tree count