QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603892#7514. Clique ChallengeMax_s_xaMWA 1ms9824kbC++173.7kb2024-10-01 20:42:332024-10-01 20:42:34

Judging History

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

  • [2024-10-01 20:42:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9824kb
  • [2024-10-01 20:42:33]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <random>
#include <ctime>
#include <chrono>
#include <iomanip>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 1010, MAXM = (1 << 22) + 5, mod = 1e9 + 7;

inline void add(int &x, int y) { (x += y) >= mod && (x -= mod); }

int n, m, to[MAXN], fr[MAXN], ans;
int deg[MAXN], id[MAXN];

vector <int> vec[MAXN];
bool g[MAXN][MAXN], f1[MAXM];
int p[MAXN], f2[MAXM];
ll e[MAXN], adj[MAXM];

int main()
{
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n), Read(m);
    for (int i = 1; i <= m; i++)
    {
        Read(fr[i]), Read(to[i]);
        deg[fr[i]]++, deg[to[i]]++;
        g[fr[i]][to[i]] = g[to[i]][fr[i]] = 1;
    }
    iota(id + 1, id + n + 1, 1);
    sort(id + 1, id + n + 1, [&](int x, int y) { return deg[x] < deg[y]; });
    for (int i = 1; i <= m; i++)
    {
        if (deg[fr[i]] > deg[to[i]]) swap(fr[i], to[i]);
        vec[fr[i]].push_back(to[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < vec[i].size(); j++) p[vec[i][j]] = j, e[j] = 0;
        for (auto x : vec[i])
            for (auto y : vec[i])
                if (g[x][y]) e[p[x]] |= (1ll << p[y]);
        int m1 = vec[i].size() / 2, m2 = vec[i].size() - m1;
        f2[0] = 1;
        for (int j = 1; j < (1 << m2); j++)
        {
            int u = __builtin_ctz(j) + m1;
            f2[j] = f2[j ^ (j & -j)] + f2[j & (e[u] >> m1)];
        }
        f1[0] = 1, adj[0] = (1 << m2) - 1, add(ans, f2[adj[0]]);
        for (int j = 1; j < (1 << m1); j++)
        {
            int u = __builtin_ctz(j);
            f1[j] = f1[j ^ (j & -j)] & ((e[u] & j) == (j ^ (j & -j)));
            adj[j] = adj[j ^ (j & -j)] & (e[u] >> m1);
            if (f1[j]) add(ans, f2[adj[j]]);
        }
    }
    cout << ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

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

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

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:

1371

result:

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