Submission #1689265
Source Code Expand
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int fastpow(int x,int a){ int ret=1; while(a){ if(a&1) ret=ret*1LL*x%mod; a>>=1;x=x*1LL*x%mod; } return ret; } #define LL long long struct Combin{ #define N 405 int fac[N],rv[N],facrv[N]; Combin(){ fac[0]=rv[1]=facrv[0]=1; for(int i=2;i<N;i++) rv[i]=((-(LL)(mod/i)*rv[mod%i]%mod)+mod)%mod; for(int i=1;i<N;i++) fac[i]=(LL)fac[i-1]*i%mod; for(int i=1;i<N;i++) facrv[i]=(LL)facrv[i-1]*rv[i]%mod; } int C(int r1,int n1){ if(r1>n1) return 0; return fac[n1]*(LL)facrv[r1]%mod*facrv[n1-r1]%mod; } #undef N }C; #define N 55 struct edge{ int t,next; }e[205];int ecnt,head[N],du[N]; void addedge(int f,int t){ e[++ecnt]=(edge){t,head[f]};head[f]=ecnt;du[f]++; e[++ecnt]=(edge){f,head[t]};head[t]=ecnt;du[t]++; } int n,m,k; int ans=1; void calc2(int sz){ int ret=0; for(int i=1;i<=sz;i++) ret=(ret+fastpow(k,__gcd(sz,i)))%mod; ans=ans*1LL*(ret*1LL*C.rv[sz]%mod)%mod; } void calc3(int sz){ ans=ans*1LL*C.C(k-1,sz+k-1)%mod; } int sz[N],mint[N],ti[N],tcnt,etcnt,vis[N]; int top,sta[205]; void tarjan(int u,int fre){ ti[u]=++tcnt;mint[u]=ti[u]; int mn=ti[u]; for(int i=head[u];i;i=e[i].next){ if((i^fre)==1) continue; if(ti[e[i].t]==0){ sta[++top]=i; tarjan(e[i].t,i); mn=min(mn,mint[e[i].t]); if(mint[e[i].t]>=ti[u]){ int n1=0,m1=0; etcnt++; while(top>0&&sta[top]!=fre&&mint[e[sta[top]].t]>=ti[u]){ m1++; if(vis[e[sta[top]].t]!=etcnt) n1++,vis[e[sta[top]].t]=etcnt; if(vis[e[sta[top]^1].t]!=etcnt) n1++,vis[e[sta[top]^1].t]=etcnt; top--; } if(m1==1) ans=ans*1LL*k%mod; else if(n1==m1) calc2(m1); else calc3(m1); } }else{ if(ti[u]>ti[e[i].t]) sta[++top]=i; mn=min(mn,mint[e[i].t]); } } mint[u]=mn; } int main(){ ecnt=1; scanf("%d%d%d",&n,&m,&k); for(int i=1,f,t;i<=m;i++) scanf("%d%d",&f,&t),addedge(f,t); for(int i=1;i<=n;i++) if(ti[i]==0) tarjan(i,0); cout<<(ans+mod)%mod<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Painting Graphs with AtCoDeer |
User | Wuvin |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 2068 Byte |
Status | AC |
Exec Time | 1 ms |
Memory | 256 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:82:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d%d",&n,&m,&k); ^ ./Main.cpp:83:60: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for(int i=1,f,t;i<=m;i++) scanf("%d%d",&f,&t),addedge(f,t); ^
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 | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
1_003.txt | AC | 1 ms | 256 KB |
1_004.txt | AC | 1 ms | 256 KB |
1_005.txt | AC | 1 ms | 256 KB |
1_006.txt | AC | 1 ms | 256 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | AC | 1 ms | 256 KB |
1_009.txt | AC | 1 ms | 256 KB |
1_010.txt | AC | 1 ms | 256 KB |
1_011.txt | AC | 1 ms | 256 KB |
1_012.txt | AC | 1 ms | 256 KB |
1_013.txt | AC | 1 ms | 256 KB |
1_014.txt | AC | 1 ms | 256 KB |
1_015.txt | AC | 1 ms | 256 KB |
1_016.txt | AC | 1 ms | 256 KB |
1_017.txt | AC | 1 ms | 256 KB |
1_018.txt | AC | 1 ms | 256 KB |
1_019.txt | AC | 1 ms | 256 KB |
1_020.txt | AC | 1 ms | 256 KB |
1_021.txt | AC | 1 ms | 256 KB |
1_022.txt | AC | 1 ms | 256 KB |
1_023.txt | AC | 1 ms | 256 KB |
1_024.txt | AC | 1 ms | 256 KB |
1_025.txt | AC | 1 ms | 256 KB |
1_026.txt | AC | 1 ms | 256 KB |
1_027.txt | AC | 1 ms | 256 KB |
1_028.txt | AC | 1 ms | 256 KB |
1_029.txt | AC | 1 ms | 256 KB |
1_030.txt | AC | 1 ms | 256 KB |
1_031.txt | AC | 1 ms | 256 KB |
1_032.txt | AC | 1 ms | 256 KB |
1_033.txt | AC | 1 ms | 256 KB |
1_034.txt | AC | 1 ms | 256 KB |
1_035.txt | AC | 1 ms | 256 KB |
1_036.txt | AC | 1 ms | 256 KB |
1_037.txt | AC | 1 ms | 256 KB |
1_038.txt | AC | 1 ms | 256 KB |
1_039.txt | AC | 1 ms | 256 KB |
1_040.txt | AC | 1 ms | 256 KB |
1_041.txt | AC | 1 ms | 256 KB |
1_042.txt | AC | 1 ms | 256 KB |
1_043.txt | AC | 1 ms | 256 KB |
1_044.txt | AC | 1 ms | 256 KB |
1_045.txt | AC | 1 ms | 256 KB |
1_046.txt | AC | 1 ms | 256 KB |
1_047.txt | AC | 1 ms | 256 KB |
1_048.txt | AC | 1 ms | 256 KB |
1_049.txt | AC | 1 ms | 256 KB |
1_050.txt | AC | 1 ms | 256 KB |
1_051.txt | AC | 1 ms | 256 KB |
1_052.txt | AC | 1 ms | 256 KB |
1_053.txt | AC | 1 ms | 256 KB |
1_054.txt | AC | 1 ms | 256 KB |
1_055.txt | AC | 1 ms | 256 KB |
1_056.txt | AC | 1 ms | 256 KB |
1_057.txt | AC | 1 ms | 256 KB |
1_058.txt | AC | 1 ms | 256 KB |
1_059.txt | AC | 1 ms | 256 KB |
1_060.txt | AC | 1 ms | 256 KB |
1_061.txt | AC | 1 ms | 256 KB |
1_062.txt | AC | 1 ms | 256 KB |
1_063.txt | AC | 1 ms | 256 KB |