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>N2.D)return 1; Else if(N1.D<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