QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#248889#7514. Clique ChallengewxhtzdyWA 1ms3468kbC++203.2kb2023-11-11 22:28:542023-11-11 22:28:55

Judging History

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

  • [2023-11-11 22:28:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3468kb
  • [2023-11-11 22:28:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<int> deg(n);
  for (int i = 0; i < n; i++) {
    deg[i] = (int) g[i].size();
  }
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&](int i, int j) {
    return deg[i] < deg[j];
  });
  vector<bool> del(n);
  vector<int> idx(n);
  vector<bool> act(n);
  long long ans = 0;
  for (int ver : order) {
    vector<int> adj;
    for (int u : g[ver]) {
      if (!del[u]) {
        adj.push_back(u);
      }
    }
    int sz = (int) adj.size();
    int L = sz / 2;
    int R = sz - L;
    vector<bool> goodL(1 << L);
    vector<bool> goodR(1 << R);
    vector<int> cnt(1 << R);
    {
      for (int i = 0; i < L; i++) {
        idx[adj[i]] = i;
        act[adj[i]] = true;
      }
      vector<int> adjL(L);
      for (int i = 0; i < L; i++) {
        for (int j : g[adj[i]]) {
          if (act[j]) {
            adjL[i] |= (1 << idx[j]);
          }
        }
      }
      for (int mask = 0; mask < (1 << L); mask++) {
        goodL[mask] = true;
        for (int i = 0; i < L; i++) {
          if (mask >> i & 1) {
            if ((adjL[i] & (mask ^ (1 << i))) != (mask ^ (1 << i))) {
              goodL[mask] = false;
            }
          }
        }
      }
      for (int i = 0; i < L; i++) {
        act[adj[i]] = false;
      }
    }
    {
      for (int i = 0; i < R; i++) {
        idx[adj[i + L]] = i;
        act[adj[i + L]] = true;
      }
      vector<int> adjR(R);
      for (int i = 0; i < R; i++) {
        for (int j : g[adj[i + L]]) {
          if (act[j]) {
            adjR[i] |= (1 << idx[j]);
          }
        }
      }
      for (int mask = 0; mask < (1 << R); mask++) {
        goodR[mask] = true;
        for (int i = 0; i < R; i++) {
          if (mask >> i & 1) {
            if ((adjR[i] & (mask ^ (1 << i))) != (mask ^ (1 << i))) {
              goodR[mask] = false;
            }
          }
        }
        cnt[mask] = goodR[mask];
      }
      for (int i = 0; i < R; i++) {
        for (int mask = 0; mask < (1 << R); mask++) {
          if (mask >> i & 1) {
            cnt[mask] += cnt[mask ^ (1 << i)];
          }
        }
      }
      for (int i = 0; i < R; i++) {
        act[adj[i + L]] = false;
      }
    }
    for (int i = 0; i < R; i++) {
      act[adj[i + L]] = true;
      idx[adj[i + L]] = i;
    }
    vector<int> f(L);
    for (int i = 0; i < L; i++) {
      for (int j : g[adj[i]]) {
        if (act[j]) {
          f[i] |= (1 << idx[j]);
        }
      }
    }
    for (int i = 0; i < R; i++) {
      act[i] = false;
    }
    for (int mask = 0; mask < (1 << L); mask++) {
      if (!goodL[mask]) {
        continue;
      }
      int maskR = (1 << R) - 1;
      for (int i = 0; i < L; i++) {
        if (mask >> i & 1) {
          maskR = (maskR & f[i]); 
        }
      }
      ans += cnt[maskR];
    }
    del[ver] = true;
  }
  cout << ans << '\n';
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3432kb

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

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

input:

3 3
1 2
1 3
2 3

output:

7

result:

ok single line: '7'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3468kb

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:

1611

result:

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