QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#295436#7514. Clique Challengesofija6WA 29ms4864kbC++232.8kb2023-12-31 06:32:292023-12-31 06:32:29

Judging History

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

  • [2023-12-31 06:32:29]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:4864kb
  • [2023-12-31 06:32:29]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define MAXN 1010
#define MAXS (1<<17)
using namespace std;
set<ll> G[MAXN];
bool act[MAXN],dpl[MAXS],dpr[MAXS];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,m,u,v;
    cin >> n >> m;
    for (ll i=1;i<=m;i++)
    {
        cin >> u >> v;
        G[u].insert(v);
        G[v].insert(u);
    }
    for (ll i=1;i<=n;i++)
        act[i]=true;
    ll cnt=n,ans=0;
    while (cnt)
    {
        vector<pair<ll,ll> > deg;
        for (ll i=1;i<=n;i++)
        {
            if (act[i])
            {
                ll c=0;
                for (ll next : G[i])
                    c+=act[next];
                deg.push_back({c,i});
            }
        }
        sort(deg.begin(),deg.end());
        u=deg[0].second;
        act[u]=false;
        cnt--;
        vector<ll> w,l,r;
        for (ll next : G[u])
        {
            if (act[next])
                w.push_back(next);
        }
        for (ll i=0;i<w.size()/2;i++)
            l.push_back(w[i]);
        for (ll i=w.size()/2;i<w.size();i++)
            r.push_back(w[i]);
        for (ll i=0;i<(1<<l.size());i++)
            dpl[i]=true;
        for (ll i=0;i<(1<<r.size());i++)
            dpr[i]=true;
        for (ll i=1;i<(1<<l.size());i++)
        {
            ll pos;
            for (ll j=0;j<l.size();j++)
            {
                if ((1<<j)&i)
                    pos=j;
            }
            for (ll j=0;j<l.size();j++)
            {
                if (j!=pos && !G[l[j]].count(l[pos]))
                    dpl[i]=false;
            }
            dpl[i]=(dpl[i] && dpl[i^(1<<pos)]);
        }
        ll sum[MAXS]={0};
        for (ll i=1;i<(1<<r.size());i++)
        {
            ll pos;
            for (ll j=0;j<r.size();j++)
            {
                if ((1<<j)&i)
                    pos=j;
            }
            for (ll j=0;j<r.size();j++)
            {
                if (j!=pos && !G[r[j]].count(r[pos]))
                    dpr[i]=false;
            }
            dpr[i]=(dpr[i] && dpr[i^(1<<pos)]);
            sum[i]=dpr[0];
            for (int j=i;j>0;j=(j-1)&i)
                sum[i]+=dpr[j];
        }
        sum[0]=1;
        for (ll i=0;i<(1<<l.size());i++)
        {
            if (!dpl[i])
                continue;
            ll mask=(1<<r.size())-1;
            for (ll j=0;j<l.size();j++)
            {
                if ((1<<j)&i)
                {
                    for (ll k=0;k<r.size();k++)
                    {
                        if ((1<<k)&mask && !G[l[j]].count(r[k]))
                            mask^=(1<<k);
                    }
                }
            }
            ans+=sum[mask];
        }
    }
    cout << ans;
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4864kb

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

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

input:

3 3
1 2
1 3
2 3

output:

7

result:

ok single line: '7'

Test #3:

score: -100
Wrong Answer
time: 29ms
memory: 4704kb

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:

1144

result:

wrong answer 1st lines differ - expected: '1373', found: '1144'