BZOJ1016: [JSOI2008] minimum spanning tree count

Source: Internet
Author: User

the sort changes to qsort on a??? Metaphysics Operation: in fact, it seems that the problem is violence. But Miss Bo seems to be doing it half the morning.

First of all must be the smallest spanning tree to find out, and then get a structure, indicating that l~r these edge values are equal, V indicates how much of this value of the edge, and then the possibility of a burst search.

#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intMod=31011;structnode{intX,y,d;} a[1100];structline{intL,r,v;} s[1100];intCNT;intcmpConst void*XX,Const void*yy) {Node N1=* (Node *) xx; Node N2=* (Node *) yy; if(N1.D&GT;N2.D)return 1; Else if(N1.D&LT;N2.D)return-1; Else return 0;}intfa[1100];intFINDFA (intx) {    if(X!=fa[x])returnFindfa (fa[x]); returnx;}intsum;voidDfsintXintIintk) {    if(i==s[x].r+1)    {        if(K==S[X].V) sum++; return ; }    intFX=FINDFA (a[i].x), fy=Findfa (A[I].Y); if(fx!=FY) {FA[FX]=fy; DFS (X,i+1, K +1); FA[FX]=fx;fa[fy]=fy; } DFS (X,i+1, k);}intMain () {intn,m; scanf ("%d%d",&n,&m);  for(intI=1; i<=m;i++) scanf ("%d%d%d",&a[i].x,&a[i].y,&A[I].D); Qsort (A+1Msizeof(node), CMP);  for(intI=1; i<=n;i++) fa[i]=i; inttot=0;  for(intI=1; i<=m;i++)    {        if(a[i].d!=a[i-1].d) {S[CNT].R=i-1; CNT++; S[CNT].L=i;s[cnt].v=0; }                intFX=FINDFA (a[i].x), fy=Findfa (A[I].Y); if(fx!=FY) {FA[FX]=fy; Tot++;s[cnt].v++; }} S[CNT].R=m; if(tot<n-1) {printf ("0\n");return 0;}  for(intI=1; i<=n;i++) fa[i]=i; intans=1;  for(intI=1; i<=cnt;i++) {sum=0; DFS (I,S[I].L,0); Ans= (ans*sum)%MoD;  for(intj=s[i].l;j<=s[i].r;j++)        {            intFX=FINDFA (a[j].x), fy=Findfa (A[J].Y); if(fx!=fy) fa[fx]=y; }} 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.