QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#295682#7514. Clique Challengesofija6TL 1ms7624kbC++233.4kb2023-12-31 18:44:442023-12-31 18:44:45

Judging History

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

  • [2023-12-31 18:44:45]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7624kb
  • [2023-12-31 18:44:44]
  • 提交

answer

#include <bits/stdc++.h>
#define ll int
#define MAXN 1010
#define MAXS (1<<25)
#define MOD 1000000007
using namespace std;
vector<ll> G[MAXN],l,r;
bool act[MAXN],dpl[MAXS],dpr[MAXS],edge[MAXN][MAXN];
ll sum[MAXS],mask1[MAXS],mm[25],deg[MAXN];
vector<pair<ll,ll> > a;
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].push_back(v);
        G[v].push_back(u);
        edge[u][v]=edge[v][u]=true;
        deg[u]++;
        deg[v]++;
    }
    for (ll i=1;i<=n;i++)
        act[i]=true;
    ll cnt=n;
    ll ans=0;
    dpl[0]=dpr[0]=true;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > > q;
    for (ll i=1;i<=n;i++)
        q.push({deg[i],i});
    while (cnt)
    {
        while (!act[q.top().second])
            q.pop();
        a.push_back(q.top());
        act[q.top().second]=false;
        q.pop();
        cnt--;
    }
    for (ll i=1;i<=n;i++)
        act[i]=true;
    for (auto b : a)
    {
        u=b.second;
        act[u]=false;
        ll minn=b.first;
        l.clear();
        r.clear();
        for (ll next : G[u])
        {
            if (act[next])
            {
                if (l.size()<=(minn+1)/2)
                    l.push_back(next);
                else
                    r.push_back(next);
            }
        }
        for (ll i=0;i<l.size();i++)
        {
            mm[i]=0;
            for (ll j=0;j<r.size();j++)
            {
                if (!edge[l[i]][r[j]])
                    mm[i]+=(1<<j);
            }
        }
        for (ll i=1;i<(1<<r.size());i++)
        {
            dpr[i]=true;
            ll pos=-1;
            for (ll j=0;j<r.size();j++)
            {
                if ((1<<j)&i)
                {
                    if (pos==-1)
                        pos=j;
                    else if (!edge[r[j]][r[pos]])
                    {
                        dpr[i]=false;
                        break;
                    }
                }
            }
            dpr[i]=(dpr[i] && dpr[i^(1<<pos)]);
        }
        for (ll i=0;i<(1<<r.size());i++)
            sum[i]=dpr[i];
        for (ll i=0;i<r.size();i++)
        {
            for (ll j=0;j<(1<<r.size());j++)
            {
                if (j&(1<<i))
                    sum[j]+=sum[j^(1<<i)];
                if (sum[j]>=MOD)
                    sum[j]-=MOD;
            }
        }
        for (ll i=1;i<(1<<l.size());i++)
        {
            dpl[i]=true;
            ll pos=-1;
            for (ll j=0;j<l.size();j++)
            {
                if ((1<<j)&i)
                {
                    if (pos==-1)
                        pos=j;
                    else if (!edge[l[j]][l[pos]])
                    {
                        dpl[i]=false;
                        break;
                    }
                }
            }
            dpl[i]=(dpl[i] && dpl[i^(1<<pos)]);
            mask1[i]=mask1[i^(1<<pos)]|mm[pos];
            if (dpl[i])
            {
                ll mask=(1<<r.size())-1;
                mask^=(mask&mask1[i]);
                ans+=sum[mask];
                if (ans>=MOD)
                    ans-=MOD;
            }
        }
        ans+=sum[(1<<r.size())-1];
    }
    cout << ans;
    return 0;
}

详细

Test #1:

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

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

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

input:

3 3
1 2
1 3
2 3

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 0ms
memory: 5600kb

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:

1373

result:

ok single line: '1373'

Test #4:

score: -100
Time Limit Exceeded

input:

1000 1000
770 105
219 498
686 498
343 534
15 591
919 588
149 588
298 915
551 523
710 116
105 637
523 991
343 476
145 420
604 588
254 120
551 421
476 298
900 710
915 343
445 421
986 867
445 588
219 356
919 105
584 875
991 604
776 919
588 254
919 421
356 348
105 551
15 113
919 15
356 523
343 155
770 9...

output:


result: