Obviously we can find the answer is the size of each set that can reach each other and then multiply it by the same order. Consider how to find a collection of each complementary phase, that is, a hash. ( However, I have taken 3 modules before )
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <vector>5#include <cstdlib>6#include <cmath>7#include <cstring>8 using namespacestd;9 #defineMAXN 1000010Ten #defineMD (LLG) (1000100000001007) One #defineMD 1000000007 A #defineMD2 (LLG) (5456145545456) - #defineMD3 (LLG) (100007) - #defineLLG Long Long the #defineYyj (a) freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout); - LLG n,m,a[maxn],p[maxn],l,r; - - structnode + { - LLG a1,a2,a3; + }C[MAXN]; A at BOOLcmpConstNode&a,Constnode&b) - { - if(a.a1==b.a1 && a.a2==b.a2)returna.a3<b.a3; - if(A.A1==B.A1)returna.a2<b.a2; - returna.a1<b.a1; - } in - intMain () to { +Srand1346); - //yyj ("C"); thep[0]=p[1]=1; * for(Llg i=2; i<=1000000; i++) p[i]=p[i-1]*i,p[i]%=MD; $Cin>>n>>m;Panax NotoginsengLLG inc=1; - for(Llg k=1; k<=n;k++) the { + LLG x; AInc=rand ()%md+1; Llg Inc2=rand ()%md+1, Inc3=rand ()%md+1; thescanf"%i64d",&x); + for(Llg i=1; i<=x;i++) - { $scanf"%i64d",&a[i]); $C[a[i]].a1+=inc; C[A[I]].A2+=INC2; c[a[i]].a3+=inc3; -C[A[I]].A1%=MD; C[A[I]].A2%=MD2; c[a[i]].a3%=md3; - } theinc*=2; -inc%=MD;Wuyi } theLLG ans=1; -Sort (c+1, c+m+1, CMP); WuL=1; - while(l<=m) About { $R=l; - while(c[r+1].A1==C[L].A1 && c[r+1].A2==C[L].A2 && c[r+1].A3==C[L].A3 && r+1<=M) r++; -ans*=p[r-l+1]; -ans%=MD; Al=r+1; + } the //For (Llg i=1;i<=c[0];i++) ans*=n,ans%=md; -cout<<ans; $ return 0; the}
Codeforces 757C Felicity is coming!