BZOJ1016: [JSOI2008] minimum spanning tree count

Source: Internet
Author: User

Surface

Transmission Door

Sol

The nature of the minimum spanning tree:

    • For each \ (mst\), the same number of edges is used for each of the edge weights
    • All (mst\) edge \ (≤w\) sides of the graph are the same connectivity

Then the problem is enumerated without a weight to select those sides, if the number of connected and the same as the original statistics
The last multiplication principle can

If the same Benquan too much, you can only use the matrix tree theorem
But I'm too good to be.

# include <bits/stdc++.h># define RG Register# define IL inline# define Fill (A, B) memset (A, B, sizeof (a))# define File (a) freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout)using namespaceStdtypedef Long LongllConst intZsy (31011);Const int_( the);Const int__(1005); ILintInput () {RGintx =0, z =1; RgCharc = GetChar (); for(; c <' 0 '|| C >' 9 '; c = GetChar ()) z = c = ='-'?-1:1; for(; C >=' 0 '&& C <=' 9 '; c = GetChar ()) x = (x <<1) + (x <<3) + (c ^ -);returnx * z;}intN, M, fa[_], ans =1, o[__], Len, l[__], r[__], id[__], cnt[__], tmp[_];structedge{intU, V, W; ILBOOL operator< (RG Edge B)Const{returnW < B.W; }} Edge[__];ilintFind (RGintx) {returnx = = Fa[x]? X:FA[X] = Find (Fa[x]);} ILintCount (RGintx) {RGintRET =0; for(; x; x-= x &-X) ++ret;returnRET;}intMain (RGintARGC, RGChar* argv[]) {n = input (), M = input (); for(RGinti =1; I <= N; ++i) Fa[i] = i; for(RGinti =1; I <= m;        ++i) {Edge[i] = (edge) {input (), input (), input ()}; O[i] = EDGE[I].W, l[i] = m, r[i] =1; } Sort (Edge +1, Edge + M +1); Sort (o +1, O + M +1), Len = unique (o +1, O + M +1)-O-1; RgintGG =0; for(RGinti =1; I <= m; ++i) {RGintFX = Find (edge[i].u), FY = find (EDGE[I].V); Id[i] = Lower_bound (o +1, O + len +1, EDGE[I].W)-O; L[id[i]] = min (L[id[i]], i), r[id[i]] = max (R[id[i]], i);if(Find (FX) = = Find (FY))Continue;    FA[FX] = FY, ++cnt[id[i]], ++gg; }if(GG! = n-1)returnPuts"0"),0; for(RGinti =1; I <= N; ++i) Fa[i] = i; for(RGinti =1; I <= Len; ++i) {RGinttot =0; for(RGintj =1; J <= N; ++J) Tmp[j] = Fa[j]; for(RGintj =0, S =1<< (R[i]-l[i] +1); J < S; ++J) {if(Count (j)! = Cnt[i])Continue; RgintFLG =0; for(RGintK =1; K <= N; ++K) Fa[k] = tmp[k]; for(RGintK =0; K <= R[i]-l[i]; ++K)if((1<< k) & j) {RGintFX = Find (Edge[k + l[i]].u), FY = find (edge[k + l[i]].v);if(FX = = FY) {FLG =1; Break;                } Fa[fx] = FY; }if(!FLG) ++tot; } ans = ans * tot% Zsy; for(RGintj =1; J <= N; ++J) Fa[j] = Tmp[j]; for(RGintj = L[i]; J <= R[i]; ++J) {RGintFX = Find (edge[j].u), FY = find (EDGE[J].V);if(FX! = FY) fa[fx] = FY; }} printf ("%d\n", ans);return 0;}

BZOJ1016: [JSOI2008] minimum spanning tree count

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.