Cnm%:
1 #include2 #include 3 #include 4 using namespace std; 5 #define LL __int64 6 #define MOD 1000000007ll 7 const LL mod = 1000000007; 8 const LL N = 100000+5; 9 const LL M=1e5+3;10 vector mp[100500];11 LL ans;12 LL n,k;13 LL vis[100500];14 LL fac[100005]; //阶乘15 LL inv_of_fac[100005]; //阶乘的逆元16 LL qpow(LL x,LL n)17 {18 LL ret=1;19 for(; n; n>>=1)20 {21 if(n&1) ret=ret*x%mod;22 x=x*x%mod;23 }24 return ret;25 }26 void init()27 {28 fac[1]=1;29 for(int i=2; i<=M; i++)30 fac[i]=fac[i-1]*i%mod;31 inv_of_fac[M]=qpow(fac[M],mod-2);32 for(int i=M-1; i>=0; i--)33 inv_of_fac[i]=inv_of_fac[i+1]*(i+1)%mod;34 }35 LL C(LL a,LL b)36 {37 if(b>a) return 0;38 if(b==0) return 1;39 return fac[a]*inv_of_fac[b]%mod*inv_of_fac[a-b]%mod;40 }41 //(C(k,n)-C(k,cont)-C(k,n-cont)+MOD)%MOD;42 LL Dfs(int u)43 {44 vis[u]=1;45 LL cont=1;46 for(LL int i=0;i