Submission #1179778


Source Code Expand

#include<bits/stdc++.h>
#include<vector>
#define N 205
#define PAIR pair<int,int>
#define LL long long
using namespace std;
const int mo=1e9+7;
int head[N],len,nxt[N],num[N],ce,cd;
int n,m,k,f[N],C[N][N],pw[N],ans,dfn[N],low[N],clk,cut[N],st[N],top,vis[N],xyk;
int gcd(int x,int y){ return x ? gcd(y%x,x) : y;}
LL fpm(LL x,LL y){ LL s=1; while(y){ if(y&1) s=(s*x)%mo; y>>=1,x=(x*x)%mo;} return s;}
int cir(int n)
{
	int i,ans=0;
	for(i=1;i<=n;i++)
		ans=(ans+pw[gcd(i,n)])%mo;
	ans=(1LL*ans*fpm(n,mo-2))%mo;
	return ans;
}
void calc(int e)
{
	int x,y;
	if(top==1) ans=(1LL*ans*k)%mo,top=0;
	else{
		cd=ce=0,++xyk;
		while(top){
			x=num[st[top]^0];
			y=num[st[top]^1];
			ce++;
			if(vis[x]!=xyk) cd++,vis[x]=xyk;
			if(vis[y]!=xyk) cd++,vis[y]=xyk;
			if(st[top--]==e) break;
		  }
		if(cd==ce) ans=(1LL*ans*cir(cd))%mo;
		else ans=(1LL*ans*C[ce+k-1][k-1])%mo;
	  }
}
void tarjan(int t,int fa)
{
	int i;
	dfn[t]=low[t]=++clk,cut[t]=0;
	for(i=head[t];i;i=nxt[i]){
		if(num[i]==fa) continue;
		if(!dfn[num[i]]){
			st[++top]=i;
			tarjan(num[i],t),low[t]=min(low[t],low[num[i]]);
			if(low[num[i]]>=dfn[t]) cut[t]=1,calc(i);
		  }
		else{
			low[t]=min(low[t],dfn[num[i]]);
			if(dfn[num[i]]<dfn[t]) st[++top]=i;
		  }
	  }
}
int main()
{
	int i,j,x,y; ans=len=1;
	scanf("%d %d %d",&n,&m,&k);
	for(i=1;i<=m;i++){
		scanf("%d %d",&x,&y);
		num[++len]=y,nxt[len]=head[x],head[x]=len;
		num[++len]=x,nxt[len]=head[y],head[y]=len;
	  }
	C[0][0]=pw[0]=1;
	for(i=1;i<N;i++){
		C[i][0]=C[i][i]=1;
		for(j=1;j<i;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
	  }
	for(i=1;i<N;i++) pw[i]=(1LL*pw[i-1]*k)%mo;
	for(i=1;i<=n;i++)
		if(!dfn[i])
			tarjan(i,0),top=0;
	cout<<ans;
	return 0;
}

Submission Info

Submission Time
Task F - Painting Graphs with AtCoDeer
User MemorySlices
Language C++14 (GCC 5.4.1)
Score 1300
Code Size 1753 Byte
Status AC
Exec Time 1 ms
Memory 384 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:58:28: 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:60:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
                       ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1300 / 1300
Status
AC × 3
AC × 64
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