|
|
вернуться в форумWhere is bug? #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> const long long mod=1000000007; const int nmax=200; int n,m,t,p; long long v[nmax],fact[nmax],step[nmax]; bool used[nmax]; bool a[nmax][nmax]; long long ans; void DFS(int v) { for(int j=1;j<=n;j++) { if(a[v][j] && !used[j]) { t++; used[j]=true; DFS(j); } } } bool FindCycle(int v,int pr) { bool f=false; for(int j=1;j<=n;j++) { if(a[v][j] && j!=pr) { if(used[j]) return true; else { used[j]=true; t++; f=f | FindCycle(j,v); } } } return f; } void main() { scanf("%d%d\n",&n,&m);
if(n<=2) { printf("1"); return; }
fact[0]=1; for(int i=1;i<=n;i++) fact[i]=fact[i-1]*((long long)i) % mod;
for(int i=1;i<=n;i++) step[i]=0;
for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) a[i][j]=false; }
for(int i=1;i<=m;i++) { scanf("%d\n",&t); if(!a[i][t]) { a[i][t]=a[t][i]=true; step[i]++; step[t]++;
} }
p=1; while(p<=n && step[p]<=2) p++; if(p<=n) { printf("0"); return; }
for(int i=1;i<=n;i++) used[i]=false;
for(int i=1;i<=n;i++) { if(!used[i]) { used[i]=true; t=1; if(FindCycle(i,-1)) { if(t<n) { printf("0"); return; } if(t==n) { printf("2"); return; } }
} }
for(int i=1;i<=n;i++) used[i]=false; p=0; ans=1; for(int i=1;i<=n;i++) { if(!used[i]) { p++; t=1; used[i]=true; DFS(i); if(t>1) t=2; ans*=((long long)t) % mod; } } ans=ans*fact[p-1] % mod; while(ans<0) ans+=mod; printf("%lld",ans); } Re: Where is bug? Test #9 is the first test with N = 100, and it's also the first with M = 100. I've generated 2k+ random tests with those parameters but got no difference between programs, so i guess it should be a quite specific test. Anyways, the right answer to that one is 950M ± 10M, and yours is 580M ± 10M. Re: Where is bug? В-общем,я в своём репертуаре. ТОТ ЖЕ ГОВНОКОД, но на ПАСКАЛЕ, дал АС! P.S. Glad to see you, Jane Soboleva!!! Re: Where is bug? Oh, i guess it was something syntax-specific then, like in a certain place there goes a wrong order of operations or something like that... P.S. Glad to see you, Jane Soboleva!!! <3 |
|
|