Submission #3231313
Source Code Expand
#include<bits/stdc++.h> #define mod 1000000007 #define N 1005 #define M 10005 #define ll long long using namespace std; inline int read(){ int ans=0; char ch=getchar(); while(!isdigit(ch))ch=getchar(); while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar(); return ans; } struct edge{int v,next;}e[M<<1]; ll ifac[M],fac[M],dfn[N],low[N],tot=0,ans=1; int n,m,k,top=0,first[N],cnt=0,stk[N],siz,rec,pot,edg; set<int>tmp; inline void add(int u,int v){e[++cnt].v=v,e[cnt].next=first[u],first[u]=cnt;} inline ll ksm(ll x,int p){ ll ret=1; while(p){ if(p&1)ret=ret*x%mod; x=x*x%mod,p>>=1; } return ret; } inline ll gcd(ll a,ll b){while(b){ll t=a;a=b,b=t%a;};return a;} inline ll polya(int x){ ll ret=0; for(int i=1;i<=x;++i)(ret+=ksm(k,gcd(x,i)))%=mod; return ret*ksm(x,mod-2)%mod; } inline ll C(int n,int m){return fac[n]*ifac[m]%mod*ifac[n-m]%mod;} inline void dfs(int p,int fa){ dfn[p]=low[p]=++tot,stk[++top]=p; for(int i=first[p];i;i=e[i].next){ int v=e[i].v; if(v==fa)continue; if(dfn[v]){low[p]=min(low[p],dfn[v]);continue;} dfs(v,p),low[p]=min(low[p],low[v]); if(low[v]>=dfn[p]){ tmp.clear(),pot=edg=0; do tmp.insert((rec=stk[top--])),++pot; while(rec!=v); tmp.insert(p),++pot; for(set<int>:: iterator it=tmp.begin();it!=tmp.end();++it)for(int k=first[*it];k;k=e[k].next)if(tmp.count(e[k].v))++edg; edg>>=1; ll ttmp; if(edg<pot)(ans*=k)%=mod; if(edg==pot)(ans*=polya(edg))%=mod; if(edg>pot)(ans*=C(edg+k-1,k-1))%=mod; } } if(!fa)--top; } int main(){ n=read(),m=read(),k=read(),ifac[0]=fac[0]=ifac[1]=1; for(int i=2;i<M;++i)ifac[i]=(mod-mod/i)*ifac[mod%i]%mod; for(int i=1;i<M;++i)fac[i]=fac[i-1]*i%mod,(ifac[i]*=ifac[i-1])%=mod; for(int i=1;i<=m;++i){ int a=read(),b=read(); add(a,b),add(b,a); } for(int i=1;i<=n;++i)if(!dfn[i])dfs(i,0); cout<<ans; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Painting Graphs with AtCoDeer |
User | idxcalcal |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 1903 Byte |
Status | AC |
Exec Time | 1 ms |
Memory | 384 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1300 / 1300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt, 1_042.txt, 1_043.txt, 1_044.txt, 1_045.txt, 1_046.txt, 1_047.txt, 1_048.txt, 1_049.txt, 1_050.txt, 1_051.txt, 1_052.txt, 1_053.txt, 1_054.txt, 1_055.txt, 1_056.txt, 1_057.txt, 1_058.txt, 1_059.txt, 1_060.txt, 1_061.txt, 1_062.txt, 1_063.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 384 KB |
0_001.txt | AC | 1 ms | 384 KB |
0_002.txt | AC | 1 ms | 384 KB |
1_003.txt | AC | 1 ms | 384 KB |
1_004.txt | AC | 1 ms | 384 KB |
1_005.txt | AC | 1 ms | 384 KB |
1_006.txt | AC | 1 ms | 384 KB |
1_007.txt | AC | 1 ms | 384 KB |
1_008.txt | AC | 1 ms | 384 KB |
1_009.txt | AC | 1 ms | 384 KB |
1_010.txt | AC | 1 ms | 384 KB |
1_011.txt | AC | 1 ms | 384 KB |
1_012.txt | AC | 1 ms | 384 KB |
1_013.txt | AC | 1 ms | 384 KB |
1_014.txt | AC | 1 ms | 384 KB |
1_015.txt | AC | 1 ms | 384 KB |
1_016.txt | AC | 1 ms | 384 KB |
1_017.txt | AC | 1 ms | 384 KB |
1_018.txt | AC | 1 ms | 384 KB |
1_019.txt | AC | 1 ms | 384 KB |
1_020.txt | AC | 1 ms | 384 KB |
1_021.txt | AC | 1 ms | 384 KB |
1_022.txt | AC | 1 ms | 384 KB |
1_023.txt | AC | 1 ms | 384 KB |
1_024.txt | AC | 1 ms | 384 KB |
1_025.txt | AC | 1 ms | 384 KB |
1_026.txt | AC | 1 ms | 384 KB |
1_027.txt | AC | 1 ms | 384 KB |
1_028.txt | AC | 1 ms | 384 KB |
1_029.txt | AC | 1 ms | 384 KB |
1_030.txt | AC | 1 ms | 384 KB |
1_031.txt | AC | 1 ms | 384 KB |
1_032.txt | AC | 1 ms | 384 KB |
1_033.txt | AC | 1 ms | 384 KB |
1_034.txt | AC | 1 ms | 384 KB |
1_035.txt | AC | 1 ms | 384 KB |
1_036.txt | AC | 1 ms | 384 KB |
1_037.txt | AC | 1 ms | 384 KB |
1_038.txt | AC | 1 ms | 384 KB |
1_039.txt | AC | 1 ms | 384 KB |
1_040.txt | AC | 1 ms | 384 KB |
1_041.txt | AC | 1 ms | 384 KB |
1_042.txt | AC | 1 ms | 384 KB |
1_043.txt | AC | 1 ms | 384 KB |
1_044.txt | AC | 1 ms | 384 KB |
1_045.txt | AC | 1 ms | 384 KB |
1_046.txt | AC | 1 ms | 384 KB |
1_047.txt | AC | 1 ms | 384 KB |
1_048.txt | AC | 1 ms | 384 KB |
1_049.txt | AC | 1 ms | 384 KB |
1_050.txt | AC | 1 ms | 384 KB |
1_051.txt | AC | 1 ms | 384 KB |
1_052.txt | AC | 1 ms | 384 KB |
1_053.txt | AC | 1 ms | 384 KB |
1_054.txt | AC | 1 ms | 384 KB |
1_055.txt | AC | 1 ms | 384 KB |
1_056.txt | AC | 1 ms | 384 KB |
1_057.txt | AC | 1 ms | 384 KB |
1_058.txt | AC | 1 ms | 384 KB |
1_059.txt | AC | 1 ms | 384 KB |
1_060.txt | AC | 1 ms | 384 KB |
1_061.txt | AC | 1 ms | 384 KB |
1_062.txt | AC | 1 ms | 384 KB |
1_063.txt | AC | 1 ms | 384 KB |