QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#200859#7514. Clique Challengeucup-team1525WA 1ms7736kbC++171.6kb2023-10-04 21:41:292023-10-04 21:41:30

Judging History

你现在查看的是最新测评结果

  • [2023-10-04 21:41:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7736kb
  • [2023-10-04 21:41:29]
  • 提交

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(){
    memset(e1,0,sizeof e1);
    memset(e2,0,sizeof e2);
    int n1=ver.size()/2,n2=(ver.size()+1)/2;
    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: 0ms
memory: 5868kb

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

3 3
1 2
1 3
2 3

output:

7

result:

ok single line: '7'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 7736kb

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'