QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#283531 | #7514. Clique Challenge | light_ink_dots | WA | 3ms | 7952kb | C++14 | 2.6kb | 2023-12-14 18:57:35 | 2023-12-14 18:57:36 |
Judging History
answer
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int mod=1e9+7;
#define int long long
int s[1<<22];
int id[3000];
vector<int>v[3000];
int e[3000][3000];
int mask[3000],msk[3000];
int dp[1<<22],mp[1<<22];
int solve(vector<int>a){
// cout<<a.size()<<endl;exit(0);
memset(id,-1,sizeof(id));
memset(mask,0,sizeof(mask));
memset(msk,0,sizeof(msk));
for(int i=0;i<a.size();i++) id[a[i]]=i;
int b=a.size()/2;
int num=(a.size()-b);
memset(s,0,sizeof(int)*(1<<b));
for(int i=0;i<a.size();i++){
for(int j=0;j<num;j++){
if(e[a[b+j]][a[i]]) mask[i]|=(1<<j);
}
for(int j=0;j<b;j++){
if(e[a[j]][a[i]]) msk[i]|=(1<<j);
}
}
memset(dp,0,sizeof(int)*(1<<b));
dp[0]=1;mp[0]=(1<<b)-1;
for(int s=1;s<(1<<num);s++){
int l=__builtin_ctz(s);
int u=s-(1<<l);
if(dp[u]==0) continue;
if((mask[b+l]&u)==u) {
dp[s]=1;
mp[s]=mp[u]&msk[l+b];
}
}
for(int u=0;u<(1<<num);u++){
if(dp[u]==0) continue;
int mask=(1<<b)-1;
mask=mp[u];
s[mask]++;
}
for(int mid=1;mid<(1<<b);mid<<=1){
for(int j=0;j<(1<<b);j+=(mid<<1)){
for(int k=0;k<mid;k++){
s[j+k]+=s[j+k+mid];
}
}
}
long long ans=0;
for(int u=0;u<(1<<b);u++){
bool fl=0;
int ma=(1<<b)-1;
for(int i=0;i<b;i++){
if(!((u>>i)&1)) continue;
ma&=msk[i];
}
if((ma&u)!=u) continue;
ans+=s[u];ans%=mod;
}
return ans%mod;
}
int n,m;
struct e{
int x,y;
}d[10000];int deg[3020];
int ban[30000];
int sol(vector<int>&a){
int pd=0;
for(int x:a) pd+=ban[x];
if(pd==n){
return 1;
}
int z=0;deg[0]=1e9;
for(int x:a){
if(ban[x]) continue;
if(deg[z]>deg[x]) z=x;
}
ban[z]=1;
// sort(a.begin(),a.end(),[&](int u,int v){
// return deg[u]>deg[v];
// });
// int z=a.back();
vector<int>tmp;
for(int i=1;i<=n;i++) if(e[i][z]&&i!=z) {
deg[i]--,tmp.push_back(i);
e[i][z]=e[z][i]=0;
}
// a.pop_back();
int cur=solve(tmp);
return cur+sol(a);
}
int32_t main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
int x,y;cin>>x>>y;
e[x][y]=e[y][x]=1;
// d[i]=e{x,y};
deg[x]++,deg[y]++;
}
for(int i=1;i<=n;i++) e[i][i]=1;
vector<int>p;
for(int i=1;i<=n;i++) p.push_back(i);
cout<<(sol(p)-1+mod)%mod;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3708kb
input:
3 2 1 2 2 3
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
3 3 1 2 1 3 2 3
output:
7
result:
ok single line: '7'
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 7952kb
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:
1378
result:
wrong answer 1st lines differ - expected: '1373', found: '1378'