QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#192649 | #7514. Clique Challenge | ucup-team859# | WA | 1ms | 3576kb | C++17 | 2.9kb | 2023-09-30 15:06:52 | 2023-09-30 15:06:52 |
Judging History
answer
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
using ull = unsigned long long;
using ll = long long;
using namespace std;
constexpr int MOD = (int) 1e9 + 7;
constexpr int MAXN = 1000;
bitset<MAXN + 1> adj[MAXN + 1];
inline void add(int& x, int y) {
x += y;
if (x >= MOD)
x -= MOD;
}
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int>> edges;
vector<int> deg(n + 1);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
edges.emplace_back(x, y);
deg[x]++, deg[y]++;
}
vector<int> order(n);
iota(order.begin(), order.end(), 1);
sort(order.begin(), order.end(), [&](const int& x, const int& y) {
return deg[x] < deg[y];
});
vector<vector<int>> g(n + 1);
for (auto edge : edges) {
int x = edge.first, y = edge.second;
if (deg[x] > deg[y]) {
swap(x, y);
}
g[x].push_back(y);
adj[x][y] = adj[y][x] = 1;
}
int answer = 0;
for (auto x : order) {
vector<int> neis;
for (auto itr : g[x]) {
neis.push_back(itr);
}
sort(neis.begin(), neis.end(), [&](const int& x, const int& y) {
return deg[x] < deg[y];
});
vector<ll> masks(neis.size());
for (int i = 0; i < (int)neis.size(); i++) {
for (int j = 0; j < (int)neis.size(); j++) {
if (adj[neis[i]][neis[j]]) {
masks[i] |= (1LL << j);
}
}
}
int size1 = (int)neis.size() / 2;
int size2 = (int)neis.size() - size1;
vector<int> dp(1 << size2);
for (int mask = 0; mask < (1 << size2); mask++) {
bool ok = true;
for (int bit = 0; bit < size2 && !ok; bit++) {
if (mask & (1 << bit)) {
if (((masks[bit + size1] >> size1) & mask) != mask) {
ok = false;
}
}
}
if (ok) {
add(dp[mask], 1);
}
}
for (int bit = 0; bit < size2; bit++) {
for (int mask = 0; mask < (1 << size2); mask++) {
if (mask & (1 << bit)) {
add(dp[mask], dp[mask ^ (1 << bit)]);
}
}
}
for (int mask = 0; mask < (1 << size1); mask++) {
ll m = (1 << (size1 + size2)) - 1;
for (int bit = 0; bit < size1; bit++) {
if (mask & (1 << bit)) {
m &= masks[bit];
}
}
m >>= size1;
add(answer, dp[m]);
}
}
cout << answer;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3456kb
input:
3 2 1 2 2 3
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
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: 3576kb
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:
1569
result:
wrong answer 1st lines differ - expected: '1373', found: '1569'