Minimum spanning tree count:
Two properties of the minimum spanning tree:
1. The number of occurrences of each edge in a different minimum spanning tree is determined
2. In a different spanning tree, when a certain edge connection is completed, the form of the Unicom block state is the same
1016: [JSOI2008] minimum spanning tree count time limit: 1 Sec Memory Limit: 162 MB
Submit: 3394 Solved: 1341
[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 Output8HINT
Source
[Submit] [Status] [Discuss]
/* ***********************************************author:ckbosscreated time:2015 May 17 Sunday 09:44 48 seconds file Name : bzoj1016.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;typedef Long Long int ll;const ll Maxn=1100;const ll mod=31011; LL n,m;struct edge{ll U,v,len;} Edge[maxn];bool CMP (Edge A,edge b) {return a.len<b.len;} LL Q; LL A[MAXN]; LL NUM[MAXN]; ll fa[110];void Init () {for (LL i=0;i<110;i++) fa[i]=i;} ll find (ll u) {if (U==fa[u]) return U;return fa[u]=find (Fa[u]);} void Kruskal () {for (ll i=0;i<m;i++) {ll u=find (EDGE[I].U); LL V=find (EDGE[I].V); LL len=edge[i].len;if (u==v) continue;else{fa[u]=v;if (A[q]!=len) a[++q]=len;num[q]++;}} ll Find2 (ll x) {if (x==fa[x]) return X;return Find2 (fa[x]);} LL part[Maxn];void dfs (LL id,ll from,ll to,ll num) {if (num==0) {part[id]++; if (part[id]>=mod) part[id]-=mod; return;} for (ll i=from;i<=to;i++) {ll u=find2 (EDGE[I].U); LL V=find2 (EDGE[I].V); if (u==v) continue;else{ll T=fa[u];fa[u]=v;dfs (id,i+1,to,num-1); fa[u]=t;}} BOOL Flag;void Link (LL id,ll from,ll to,ll num) {if (flag) return; if (num==0) {flag=true; return;} for (ll i=from;i<=to&&flag==false;i++) {ll u=find2 (EDGE[I].U); LL V=find2 (EDGE[I].V); if (u==v) Continue;else{ll t=fa[u];fa[u]=v; Link (id,i+1,to,num-1); if (flag) return; fa[u]=t;}}} int main () {//freopen ("In.txt", "R", stdin),//freopen ("OUT.txt", "w", stdout); init (); scanf ("%lld%lld", &n,&m) ; for (LL i=0,u,v,w;i<m;i++) {scanf ("%lld%lld%lld", &u,&v,&w); edge[i]= (Edge) {u,v,w};} Sort (edge,edge+m,cmp); Kruskal (); int go=find (1); for (int i=2;i<=n;i++) {if (Go==find (i)) continue;else {go=-1; break ; }}if (Go==-1) {puts ("0"); return 0;} Init (); ll From=0,to=0;for (ll i=1;i<=q;i++) {for (ll j=from;j<m;j++) if (Edge[j].len==a[i])To=j;dfs (I,from,to,num[i]); flag=false; Link (I,from,to,num[i]); from=to+1;} ll Ans=part[1]%mod;for (ll i=2;i<=q;i++) {ans*=part[i];ans%=mod;} printf ("%lld\n", ans%mod); return 0;}
Bzoj 1016: [JSOI2008] minimum spanning tree count