Submission #3357436


Source Code Expand

#include<cstdio>

const int P=1000000007;
int n,d[305],fac[305],inv[305],f[305][305][2],ans;

int power(int a,int x){
	int ans=1;
	for(;x;x>>=1,a=1ll*a*a%P)if(x&1)ans=1ll*ans*a%P;
	return ans;
}
void upd(int &x,int y){x=x+y>=P?x+y-P:x+y;}

int main(){
	scanf("%d",&n);
	bool cir=true;
	for(int i=1;i<=n;i++)scanf("%d",d+i),cir&=d[i]==2;
	for(int i=fac[0]=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%P;
	inv[n]=power(fac[n],P-2);
	for(int i=n;i;i--)inv[i-1]=1ll*inv[i]*i%P;
	if(cir&&n>=3)ans=1ll*fac[n-1]*inv[2]%P;
	f[0][0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=n;j++)
			for(int k=0;k<2;k++){
				if(!f[i][j][k])continue;
				upd(f[i+1][j][k],f[i][j][k]);
				if(d[i+1]>=2)
					upd(f[i+1][j+1][k],1ll*f[i][j][k]*(d[i+1]-1)%P);
				if(!k&&d[i+1]>=3)
					upd(f[i+1][j+1][1],1ll*f[i][j][k]*(d[i+1]-1)%P*(d[i+1]-2)%P);
			}
	for(int i=3;i<n;i++)
		upd(ans,1ll*fac[i-1]*inv[2]%P*f[n][i][1]%P*fac[n-i-1]%P);
	for(int i=1;i<=n;i++)ans=1ll*ans*inv[d[i]-1]%P;
	printf("%d\n",ans);
	return 0;
}

Submission Info

Submission Time
Task F - Unicyclic Graph Counting
User luogu_bot3
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 983 Byte
Status AC
Exec Time 1 ms
Memory 896 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:14:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:16:51: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++)scanf("%d",d+i),cir&=d[i]==2;
                                                   ^

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3 All
Score / Max Score 0 / 0 200 / 200 200 / 200 300 / 300 300 / 300
Status
AC × 2
AC × 9
AC × 18
AC × 28
AC × 39
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt
Subtask1 00_example_01.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt
Subtask2 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt
Subtask3 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt, s3_21.txt, s3_22.txt, s3_23.txt, s3_24.txt, s3_25.txt, s3_26.txt
All 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt, s3_21.txt, s3_22.txt, s3_23.txt, s3_24.txt, s3_25.txt, s3_26.txt, s4_27.txt, s4_28.txt, s4_29.txt, s4_30.txt, s4_31.txt, s4_32.txt, s4_33.txt, s4_34.txt, s4_35.txt, s4_36.txt, s4_37.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 128 KB
00_example_02.txt AC 1 ms 256 KB
s1_01.txt AC 1 ms 128 KB
s1_02.txt AC 0 ms 128 KB
s1_03.txt AC 1 ms 128 KB
s1_04.txt AC 0 ms 128 KB
s1_05.txt AC 1 ms 128 KB
s1_06.txt AC 1 ms 128 KB
s1_07.txt AC 1 ms 128 KB
s1_08.txt AC 1 ms 128 KB
s2_09.txt AC 1 ms 256 KB
s2_10.txt AC 1 ms 256 KB
s2_11.txt AC 1 ms 256 KB
s2_12.txt AC 1 ms 256 KB
s2_13.txt AC 1 ms 256 KB
s2_14.txt AC 1 ms 256 KB
s2_15.txt AC 1 ms 256 KB
s2_16.txt AC 1 ms 256 KB
s3_17.txt AC 1 ms 256 KB
s3_18.txt AC 1 ms 256 KB
s3_19.txt AC 1 ms 256 KB
s3_20.txt AC 1 ms 256 KB
s3_21.txt AC 1 ms 256 KB
s3_22.txt AC 1 ms 256 KB
s3_23.txt AC 1 ms 256 KB
s3_24.txt AC 1 ms 256 KB
s3_25.txt AC 1 ms 256 KB
s3_26.txt AC 1 ms 256 KB
s4_27.txt AC 1 ms 512 KB
s4_28.txt AC 1 ms 384 KB
s4_29.txt AC 1 ms 768 KB
s4_30.txt AC 1 ms 512 KB
s4_31.txt AC 1 ms 896 KB
s4_32.txt AC 1 ms 896 KB
s4_33.txt AC 1 ms 896 KB
s4_34.txt AC 1 ms 896 KB
s4_35.txt AC 1 ms 896 KB
s4_36.txt AC 1 ms 896 KB
s4_37.txt AC 1 ms 896 KB