1 solutions
-
0
/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 神兽保佑 永无BUG */ /* * @Description: I want to be the weakest vegetable in the world! * @Author: I.Z. */ #include<bits/stdc++.h> using namespace std; #define MOD 1000000007 #define speMOD 2933256077ll #define int long long #define pii pair<int,int> #define all(v) v.begin(),v.end() #define pb push_back #define REP(i,b,e) for(int i=(b);i<(int)(e);++i) #define over(x) {cout<<(x)<<endl;return;} #define lowbit(x) ((x)&(-(x))) #define cntbit(x) __builtin_popcount(x) #define rf(v) shuffle(all(v),sd); #define deal(v) sort(all(v));v.erase(unique(v.begin(),v.end()),v.end()) mt19937 sd(std::random_device{}()); int qpow (int a,int b,int m=MOD,int res=1){ a%=m; while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1; return res; } string YN(bool x,string Y="Yes",string N="No") { if(x){ return Y; } else { return N; } } int fac[2000005],inv[2000005]; void init(int n){ fac[0]=inv[0]=1; REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD; inv[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD; } int binom(int x,int y){ return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD; } struct matrix{ int a,b,c,d; matrix operator *(matrix e){ return matrix{(a*e.a+b*e.c)%MOD,(a*e.b+b*e.d)%MOD,(c*e.a+d*e.c)%MOD,(c*e.b+d*e.d)%MOD}; } }M[100005]; struct edge{ int x,sm,df; }; int n,m,l; vector<int>v[100005],t[100005]; vector<edge>g[100005]; int deg[100005],dp[100005],fa[100005],cost[100005]; int d[15][100005],p[2100][2100]; int findfa(int x){return fa[x]==x? x:fa[x]=findfa(fa[x]);} void Main() { cin>>n>>m>>l; REP(i,0,m){ int x,y; cin>>x>>y; --x,--y; v[x].pb(y);v[y].pb(x); ++deg[x];++deg[y]; } if(m==n-1)over(qpow(l-1,n-1)*l%MOD) if(l==1)over(n==1) int ans=l; queue<int>q; REP(i,0,n)if(deg[i]==1)q.push(i); while(!q.empty()){ int x=q.front();q.pop();(ans*=l-1)%=MOD; for(auto i:v[x]){ --deg[i]; if(deg[i]==1)q.push(i); } } // cout<<ans<<endl; M[0]={1,0,0,1}; REP(i,1,100001)M[i]=M[i-1]*matrix{0,l-1,1,l-2}; REP(i,0,n)fa[i]=i; REP(i,0,n)if(deg[i]==2){ for(auto j:v[i])if(deg[j]==2&&findfa(i)!=findfa(j)&&i<j){ int x=fa[i],y=fa[j]; dp[x]+=dp[y]+1;fa[y]=x; }else if(deg[j]==2&&i<j)(ans*=M[dp[findfa(i)]].b)%=MOD; } REP(i,0,n)if(deg[i]==2)for(auto j:v[i])if(deg[j]>2)t[findfa(i)].pb(j); vector<int>V; REP(i,0,n)if(deg[i]==2&&fa[i]==i&&t[i].size()){ int x=t[i][0],y=t[i][1]; if(x==y){ (ans*=M[dp[i]+1].b)%=MOD; continue; } int z=M[dp[i]+2].b*qpow(l-1,MOD-2)%MOD; g[x].pb(edge{y,M[dp[i]+2].a,z}); g[y].pb(edge{x,M[dp[i]+2].a,z}); }else if(deg[i]>2)V.pb(i); // cout<<ans<<endl; for(auto i:V){ for(auto j:v[i])if(deg[j]>2){ g[i].pb({j,0,1}); } } for(auto i:V){ REP(j,0,g[i].size())g[i][j].x=lower_bound(all(V),g[i][j].x)-V.begin(); } REP(i,0,V.size())g[i]=g[V[i]]; n=V.size(); if(!n)over(ans) (ans*=qpow(l,MOD-2))%=MOD; REP(i,1,(1<<n)){ cost[i]=1; REP(j,0,n)if((i>>j)&1){ for(auto k:g[j])if((i>>k.x)&1)if(j<k.x)(cost[i]*=k.sm)%=MOD; } // cout<<i<<' '<<cost[i]<<endl; p[i][0]=1; REP(j,1,(1<<n))if(!(i&j)){ int x=__builtin_ctz(j); p[i][j]=p[i][j^(1<<x)]; for(auto k:g[x])if((i>>k.x)&1)(p[i][j]*=k.df)%=MOD; // cout<<i<<' '<<j<<' '<<p[i][j]<<endl; } } d[0][0]=1; REP(i,0,n){ REP(j,0,(1<<n))if(d[i][j]){ int _=(1<<n)-1;_^=j; for(int k=_;k;k=(k-1)&_)(d[i+1][j|k]+=d[i][j]*p[k][j]%MOD*cost[k])%=MOD; } } // REP(i,0,(1<<n)){ // REP(j,0,n)cout<<((i>>j)&1); // cout<<':'; // REP(j,1,n+1)cout<<d[j][i]<<' '; // cout<<endl; // } int r=0,coef=l; REP(i,1,n+1){ // cout<<coef<<' '<<d[i][(1<<n)-1]<<endl; (r+=coef*d[i][(1<<n)-1])%=MOD; coef=coef*(l-i)%MOD*qpow(i+1,MOD-2)%MOD; } cout<<r*ans%MOD<<endl; } void TC() { int tc=1; while(tc--){ Main(); cout.flush(); } } signed main() { freopen("A.in","r",stdin); freopen("A.out","w",stdout); return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0; } /* 1. CLEAR the arrays (ESPECIALLY multitests) 2. DELETE useless output */
- 1
Information
- ID
- 2918
- Time
- 4000ms
- Memory
- 512MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 4
- Accepted
- 2
- Uploaded By