QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#192768#7514. Clique Challengeucup-team859#WA 1ms3664kbC++173.2kb2023-09-30 15:27:432023-09-30 15:27:44

Judging History

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

  • [2023-09-30 15:27:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3664kb
  • [2023-09-30 15:27:43]
  • 提交

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<int> where(n + 1);
    for (int i = 0; i < n; i++) {
        where[order[i]] = i;
    }

    vector<vector<int>> g(n + 1);
    for (auto edge : edges) {
        int x = edge.first, y = edge.second;
        if (where[x] > where[y]) {
            swap(x, y);
        }
        g[x].push_back(y);
        adj[x][y] = adj[y][x] = 1;
    }

    for (int i = 1; i <= n; i++) {
        adj[i][i] = true;
    }

    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 where[x] < where[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 = (1LL << (size1 + size2)) - 1;
            bool ok = true;
            for (int bit = 0; bit < size1; bit++) {
                if (mask & (1 << bit)) {
                    m &= masks[bit];
                }
            }
            if ((mask & m) == mask) {
                add(answer, dp[m >> size1]);
            }
        }
    }

    cout << answer;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

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

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

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:

1445

result:

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