QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304938#7514. Clique ChallengeNemanjaSo2005WA 67ms3740kbC++142.7kb2024-01-14 07:22:042024-01-14 07:22:05

Judging History

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

  • [2024-01-14 07:22:05]
  • 评测
  • 测评结果:WA
  • 用时:67ms
  • 内存:3740kb
  • [2024-01-14 07:22:04]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll N,M;
ll res=0;
const int maxn=1e3+5;
const ll MOD=1e9+7;
bool povezan[maxn][maxn],bio[maxn];
vector<ll> graf[maxn];
ll mindeg(){
   int koji=0;
   for(int i=1;i<=N;i++)
      if(!bio[i] and (graf[i].size()<graf[koji].size() or koji==0))
         koji=i;
   return koji;
}
vector<ll> V;
ll cmask[105],pmask[105],mid,vred[(1<<25)];
void rek1(ll gde,ll mask1,ll mask2){
   if(gde==mid+1){
      vred[mask2]++;
      return;
   }
   rek1(gde+1,mask1,mask2);
   if((cmask[gde]&mask1)==mask1)
      rek1(gde+1,mask1|pmask[gde],mask2&cmask[gde]);
}
void rek2(ll gde,ll mask){
   if(gde==V.size()){
    //  cout<<"KRAJ "<<mask<<endl;
      res=res+vred[mask];
      if(res>=MOD)
         res-=MOD;
      return;
   }
   rek2(gde+1,mask);
  // cout<<mask<<" maske "<<cmask[gde]<<endl;
   if((mask&cmask[gde])==mask)
      rek2(gde+1,mask|pmask[gde]);
}
void resi(){
   if(V.size()==0){
      res++;
      if(res>=MOD)
         res-=MOD;
      return;
   }
   if(V.size()==1){
      res+=2;
      if(res>=MOD)
         res-=MOD;
      return;
   }
   mid=V.size()-1;

   memset(cmask,0,sizeof(cmask));
   memset(pmask,0,sizeof(pmask));

   for(ll i=0;i<V.size();i++)
      pmask[i]=(1<<(V.size()-i-1));

   for(ll i=0;i<V.size();i++)
      for(ll j=0;j<V.size();j++)
         if(povezan[V[i]][V[j]])
            cmask[i]|=pmask[j];

   for(ll i=0;i<=(1<<(V.size()-mid))-1;i++)
      vred[i]=0;

   rek1(0,0,(1<<(V.size()-mid))-1);

   /*for(int i=0;i<16;i++){
      cout<<i<<" "<<vred[i]<<endl;
   }
   cout<<endl;
*/
   for(ll i=(1<<(V.size()-mid-1));i>=1;i>>=1){
      for(ll j=(1<<(V.size()-mid))-1;j>=0;j--)
         if(j&i)
            vred[j^i]+=vred[j];
   }
  /* for(int i=0;i<16;i++){
      cout<<i<<" "<<vred[i]<<endl;
   }
   cout<<endl;*/
   rek2(mid+1,0);

}
int main(){
   cin>>N>>M;

   int a,b;
   while(M--){
      cin>>a>>b;
      povezan[a][b]=povezan[b][a]=true;
      graf[a].push_back(b);
      graf[b].push_back(a);
   }
   while(true){
      int gde=mindeg();
      if(gde==0)
         break;
      bio[gde]=true;
      V=graf[gde];

      resi();

      graf[gde].clear();
      for(int i=1;i<=N;i++){
         if(graf[i].size()==0)
            continue;
         for(int j=0;j+1<graf[i].size();j++)
            if(graf[i][j]==gde)
               swap(graf[i][j],graf[i][j+1]);
         if(graf[i].back()==gde)
            graf[i].pop_back();
      }

   }
   cout<<res<<"\n";
}
/*
14 21
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
4 6
4 7
4 8
4 14
9 14
9 10
10 14
11 14
12 13
12 14
13 14
*/

詳細信息

Test #1:

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

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

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

input:

3 3
1 2
1 3
2 3

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3740kb

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
Wrong Answer
time: 67ms
memory: 3732kb

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:

9464365

result:

wrong answer 1st lines differ - expected: '6621319', found: '9464365'