QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200870 | #7514. Clique Challenge | ucup-team1525 | WA | 2ms | 8148kb | C++17 | 1.6kb | 2023-10-04 21:50:25 | 2023-10-04 21:50:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e3,S=1<<22;
const int mod=1e9+7;
int add(int x,int y){ return (x+=y)>=mod?x-mod:x; }
int n,m;
int d[N+5],e[N+5][N+5];
int p[N+5];
int f[S+5],g[N+5];
vector<int> ver;
int e1[50],e2[50];
bool cmp(int x,int y){ return d[x]<d[y]; }
int solve(){
int n1=ver.size()/2,n2=(ver.size()+1)/2;
assert(n1+n2==ver.size());
int ans=0;
for(int i=0;i<n1+n2;i++){
e1[i]=0;
for(int j=0;j<n1;j++)
if(e[ver[i]][ver[j]])
e1[i]|=1<<j;
}
for(int i=n1;i<n1+n2;i++){
e2[i]=0;
for(int j=n1;j<n1+n2;j++)
if(e[ver[i]][ver[j]])
e2[i]|=1<<(j-n1);
}
f[0]=1;
for(int i=1;i<(1<<n1);i++){
int k=0; while(!(i>>k&1)) k++;
f[i]=f[i^(1<<k)]+f[e1[k]&i];
}
g[0]=(1<<n1);
for(int i=0;i<(1<<n2);i++){
if(!g[i]) continue;
ans=add(ans,f[g[i]-1]);
for(int k=0;k<n2&&!(i>>k&1);k++)
if((e2[k+n1]&i)==i)
g[i|(1<<k)]=((g[i]-1)&e1[k+n1])+1;
else
g[i|(1<<k)]=0;
}
return ans;
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1,u,v;i<=m;i++){
scanf("%d %d",&u,&v);
e[u][v]=e[v][u]=1;
d[u]++; d[v]++;
}
for(int i=1;i<=n;i++) p[i]=i;
sort(p+1,p+1+n,cmp);
int ans=0;
for(int i=1;i<=n;i++){
ver.clear();
for(int j=i+1;j<=n;j++)
if(e[p[i]][p[j]]) ver.push_back(p[j]);
ans=add(ans,solve());
// printf("%d\n",ans);
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5880kb
input:
3 2 1 2 2 3
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5836kb
input:
3 3 1 2 1 3 2 3
output:
7
result:
ok single line: '7'
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 8148kb
input:
1000 100 446 789 167 547 254 777 777 185 33 446 777 847 185 877 757 167 72 383 847 446 254 478 959 185 757 446 847 959 959 167 757 847 747 757 446 167 989 757 547 777 33 747 33 254 254 843 33 547 446 980 877 205 185 72 980 959 33 205 877 757 33 847 478 843 757 478 167 877 72 789 877 959 980 478 167 ...
output:
1383
result:
wrong answer 1st lines differ - expected: '1373', found: '1383'