QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202145#7514. Clique Challengeucup-team2112WA 1ms3804kbC++204.8kb2023-10-05 20:10:142023-10-05 20:10:16

Judging History

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

  • [2023-10-05 20:10:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3804kb
  • [2023-10-05 20:10:14]
  • 提交

answer

#include <bits/stdc++.h>

const int mod = 1e9 + 7;
using i64 = long long;

int norm(int x) {
    if (x < 0) {
        x += mod;
    }
    if (x >= mod) {
        x -= mod;
    }
    return x;
}
 
template<class T>
T power(T a, int b) {
    T res = 1;
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}
 
struct mint {
    int x;
    mint(int x = 0) : x(norm(x)) {}
    int val() const {
        return x;
    }
    mint operator-() const {
        return mint(norm(mod - x));
    }
    mint inv() const {
        assert(x != 0);
        return power(*this, mod - 2);
    }
    mint &operator*=(const mint &rhs) {
        x = i64(x) * rhs.x % mod;
        return *this;
    }
    mint &operator+=(const mint &rhs) {
        x = norm(x + rhs.x);
        return *this;
    }
    mint &operator-=(const mint &rhs) {
        x = norm(x - rhs.x);
        return *this;
    }
    mint &operator/=(const mint &rhs) {
        return *this *= rhs.inv();
    }
    friend mint operator*(const mint &lhs, const mint &rhs) {
        mint res = lhs;
        res *= rhs;
        return res;
    }
    friend mint operator+(const mint &lhs, const mint &rhs) {
        mint res = lhs;
        res += rhs;
        return res;
    }
    friend mint operator-(const mint &lhs, const mint &rhs) {
        mint res = lhs;
        res -= rhs;
        return res;
    }
    friend mint operator/(const mint &lhs, const mint &rhs) {
        mint res = lhs;
        res /= rhs;
        return res;
    }
    friend std::istream &operator>>(std::istream &is, mint &a) {
        i64 v;
        is >> v;
        a = mint(v);
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint &a) {
        return os << a.val();
    }
};

using i64 = long long;

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int n, m;
    std::cin >> n >> m;
    // int n = 45;
    // int m = 45 * 44 / 2;
    std::vector<std::pair<int, int> > edges(m);
    std::vector<int> cnt(n), ord(n);
    for (auto &[x, y] : edges) {
        std::cin >> x >> y;
        --x, --y;
        ++cnt[x], ++cnt[y];
    }
    // int o = 0;
    // for (int x = 0; x < n; x += 1) {
    //     for (int y = x + 1; y < n; y += 1) {
    //         edges[o++] = {x, y};
    //         ++cnt[x], ++cnt[y];
    //     }
    // }
    std::iota(ord.begin(), ord.end(), 0);
    std::sort(ord.begin(), ord.end(), [&](int x, int y) {
        if (cnt[x] != cnt[y]) {
            return cnt[x] < cnt[y];
        }
        return x < y;
    });
    std::vector adj(n, std::vector<int>());
    for (auto [x, y] : edges) {
        if (ord[x] < ord[y]) {
            adj[x].push_back(y);
        } else {
            adj[y].push_back(x);
        }
    }
    for (int i = 0; i < n; i += 1) {
        std::sort(adj[i].begin(), adj[i].end(), [&](int x, int y) {
            if (cnt[x] != cnt[y]) {
                return cnt[x] < cnt[y];
            }
            return x < y; 
        });
    }
    auto solve = [&](int s) {
        std::vector<int> label(n, -1);
        std::vector<int> rk(n, -1);
        std::vector<i64> e_mask(n);
        int o = 0;
        for (auto x : adj[s]) {
            rk[o] = x;
            label[x] = o++;
        }
        
        for (auto x : adj[s]) {
            for (auto y : adj[x]) {
                if (label[y] != -1) {
                    e_mask[label[x]] |= 1ll << label[y];
                }
            }
        }

        std::vector<mint> cnt(1 << (o - o / 2));
        auto dfs1 = [&](auto self, int u, i64 mask) {
            if (u == o / 2) {
                cnt[mask >> (o / 2)] += 1;
                return;
            }
            self(self, u + 1, mask);
            if (mask >> u & 1) {
                self(self, u + 1, mask & e_mask[u]);
            }
        };
        dfs1(dfs1, 0, (1ll << o) - 1);
        for (int i = 0; i < (o - o / 2); i += 1) {
            for (int mask = 0; mask < cnt.size(); mask += 1) {
                if (mask >> i & 1) {
                    cnt[mask ^ (1 << i)] += cnt[mask];
                }
            }
        }
        mint res = 0;
        auto dfs2 = [&](auto self, int u, i64 mask, i64 cur) {
            if (u == o) {
                cur >>= o / 2;
                res += cnt[cur];
                return;
            }
            self(self, u + 1, mask, cur);
            if (mask >> u & 1) {
                self(self, u + 1, mask & e_mask[u], cur | 1ll << u);
            }
        };
        dfs2(dfs2, o / 2, (1ll << o) - 1, 0);
        return res;
    };

    mint res = 0;
    for (int i = 0; i < n; i += 1) {
        res += solve(i);
    }
    std::cout << res << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

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

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

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:

1179

result:

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