QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199139#7514. Clique Challengeucup-team1883WA 0ms4004kbC++172.8kb2023-10-03 21:35:572023-10-03 21:35:57

Judging History

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

  • [2023-10-03 21:35:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4004kb
  • [2023-10-03 21:35:57]
  • 提交

answer

#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <cstdint>
using namespace std;

using ll = long long;
using ull = unsigned long long;

#define LOG(f...) fprintf(stderr, f)
#define DBG(f...) printf("%3d: ", __LINE__), printf(f)
// #define DBG(f...) void()
#define all(cont) begin(cont), end(cont)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

template <class T> void read(T &x) {
  char ch; x = 0;
  int f = 1;
  while (isspace(ch = getchar()));
  if (ch == '-') ch = getchar(), f = -1;
  do x = x * 10 + (ch - '0'); while (isdigit(ch = getchar()));
  x *= f;
}
template <class T, class ...A> void read(T &x, A&... args) { read(x); read(args...); }

const int N = 1005;
const int L = 32;

int n, m;
vector<int> G[N];

ll count_clique(vector<int> V) {
  // printf("cc : ");
  // for (int v : V)
  //   printf("%d ", v);
  // puts("");
  if (V.empty()) return 1;
  assert(V.size() <= 32);
  using bs = uint32_t;
  int n = V.size(), n1 = n / 2, n2 = n - n1;
  vector<bs> g(V.size()), inter1(1 << n1), inter2(1 << n2), sum(1 << n1);
  for (int i = 0; i < n; ++i)
    g[i] = 1u << i;
  for (int u = 0; u < n1; ++u)
    for (int _v : G[V[u]]) {
      int v = find(all(V), _v) - V.begin();
      if (v != n) g[u] |= 1u << v, g[v] |= 1u << u;//, printf("edge %d %d\n", u, v);
    }
  inter1[0] = inter2[0] = (1u << n) - 1;
  sum[0] = 1;
  for (bs s = 1; s < (1u << n1); ++s) {
    inter1[s] = g[__builtin_ctz(s)] & inter1[s & (s - 1)];
    sum[s] = (inter1[s] & s) == s;
  }
  for (int b = 0; b < n1; ++b)
    for (int i = 0; i < (1 << n1); i += (2 << b))
      for (int j = i; j < i + (1 << b); ++j)
        sum[j + (1 << b)] += sum[j];
  for (bs s = 1; s < (1u << n2); ++s)
    inter2[s] = g[__builtin_ctz(s) + n1] & inter2[s & (s - 1)];//, printf("inter2[%d] = %d\n", s, inter2[s]);
  ll ans = 0;
  bs mask1 = (1u << n1) - 1;
  for (bs s = 0; s < (1u << n2); ++s)
    if ((inter2[s] & (s << n1)) == (s << n1)) ans += sum[inter2[s] & mask1];//, printf("add %d\n", inter2[s] & mask1);
  // printf("ret %lld\n", ans);
  return ans;
}

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  read(n, m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    read(u, v);
    G[u].push_back(v); G[v].push_back(u);
  }
  vector<int> large;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (G[i].size() <= L) {
      vector<int> V;
      for (int v : G[i])
        if (v >= i || G[v].size() > L) V.push_back(v);
      ans += count_clique(V);
    }
    else large.push_back(i);
  }
  ans += count_clique(large);
  printf("%lld\n", (ans - 1) % 1000000007);
  return 0;
}

详细

Test #1:

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

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

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

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: 3788kb

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:

1260

result:

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