QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#710093 | #7514. Clique Challenge | test_algth | WA | 1ms | 5904kb | C++14 | 3.0kb | 2024-11-04 18:38:09 | 2024-11-04 18:38:09 |
Judging History
answer
#include <bits/stdc++.h>
const int MAXN = 2024;
const int P = 1e9 + 7;
int N, M, ans;
std::vector <int> adj[MAXN];
int deg[MAXN], I[MAXN], rk[MAXN], permits[1 << 20];
std::bitset <MAXN> vis[MAXN];
inline int add(int a, int b) {
return a -= (a += b) >= P ? P : 0;
}
inline void incr(int& a, int b) {
a = add(a, b);
}
std::pair <std::vector <int>, std::vector <int>> solve(std::vector <int> nodes) {
int n = nodes.size();
std::vector <int> f(1 << n, 0), g(1 << n, 0);
f[0] = 1, g[0] = 1;
for (int s = 0; s < (1 << n); ++s) permits[s] = (1 << n) - 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (!vis[nodes[i]][nodes[j]]) {
permits[1 << i] -= 1 << j;
}
}
}
for (int s = 1; s < (1 << n); ++s) {
int now = s & -s;
permits[s] = permits[s - now] & permits[now];
if (g[s - now] && (permits[s - now] & now) && ((permits[now] & (s - now)) == (s - now)))
g[s] = f[s] = 1;
}
for (int i = 0; i < n; ++i) {
for (int s = 0; s < (1 << n); ++s) {
if (s >> i & 1) {
incr(f[s], f[s ^ (1 << i)]);
}
}
}
return {f, g};
}
inline int calc(std::vector <int> nodes) {
int n = nodes.size();
if (n == 1) return 1;
std::vector <int> leftNodes, rightNodes;
for (int i = 0; i < (n >> 1); ++i) {
leftNodes.push_back(nodes[i]);
}
for (int i = n >> 1; i < n; ++i) {
rightNodes.push_back(nodes[i]);
}
// std::cout << "nodes : ";
// for (int i = 0; i < n; ++i) {
// std::cout << nodes[i] << " \n"[i == n - 1];
// }
auto [leftF, leftG] = solve(leftNodes);
auto [rightF, rightG] = solve(rightNodes);
int leftN = leftNodes.size();
int rightN = rightNodes.size();
std::vector <int> permit(1 << leftN, (1 << rightN) - 1);
for (int i = 0; i < leftN; ++i) {
for (int j = 0; j < rightN; ++j) {
if (!vis[leftNodes[i]][rightNodes[j]]) {
permit[1 << i] -= 1 << j;
}
}
}
int all = 0;
for (int s = 0; s < (1 << leftN); ++s) {
if (leftG[s] && (s & 1)) {
int t = (1 << rightN) - 1;
int now = s & -s;
permit[s] = permit[s ^ now] & permit[now];
t &= permit[s];
incr(all, rightF[t]);
}
}
return all;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::cin >> N >> M;
for (int i = 1, u, v; i <= M; ++i) {
std::cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
++deg[u], ++deg[v];
vis[u][v] = vis[v][u] = 1;
}
std::iota(I + 1, I + 1 + N, 1);
std::sort(I + 1, I + 1 + N, [&](const int a, const int b) { return deg[a] < deg[b]; });
for (int i = 1; i <= N; ++i) rk[I[i]] = i;
for (int i = 1; i <= N; ++i) {
int u = I[i];
std::vector <int> nodes = {u};
for (int v : adj[u]) {
if (rk[v] > i) {
nodes.push_back(v);
}
}
incr(ans, calc(nodes));
}
std::cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
3 2 1 2 2 3
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5904kb
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: 3716kb
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:
1534
result:
wrong answer 1st lines differ - expected: '1373', found: '1534'