Submission #696764

#TimeUsernameProblemLanguageResultExecution timeMemory
696764vjudge1Amusement Park (CEOI19_amusementpark)C++17
100 / 100
2363 ms3612 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define fir first
#define sec second
typedef vector <int> vi;
typedef vector <ll> vl;
template <typename __Tp> void read(__Tp &x) {
    int f = 0; x = 0; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = 1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    if (f) x = -x;
}
template <typename __Tp1, typename ...__Tp2> void read(__Tp1 &x, __Tp2 &...y) { read(x), read(y...); }
template <typename __Tp> void write(__Tp x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + 48);
}
void write(char ch) { putchar(ch); }
template <typename __Tp1, typename ...__Tp2> void write(__Tp1 x, __Tp2 ...y) { write(x), write(y...); }

const int mod = 998244353, inv2 = 499122177;
int n, m, e[20], vld[1 << 18], popcnt[1 << 18], lg[1 << 18], f[1 << 18];

int main() {
    read(n, m);
    for (int i = 1; i <= m; ++i) {
        int u, v; read(u, v), --u, --v;
        e[u] |= (1 << v), e[v] |= (1 << u);
    }
    int S = (1 << n) - 1;
    for (int i = 0; i < n; ++i) lg[1 << i] = i;
    vld[0] = 1;
    for (int s = 1; s <= S; ++s) {
        int i = lg[s & -s];
        popcnt[s] = popcnt[s & (s - 1)] + 1;
        vld[s] = vld[s & (s - 1)] & !(e[i] & s);
    }
    f[0] = 1;
    for (int s = 1; s <= S; ++s)
        for (int t = s; t; t = (t - 1) & s)
            if (vld[t]) {
                if (popcnt[t] & 1) f[s] = (f[s] + f[s ^ t]) % mod;
                else f[s] = (f[s] + mod - f[s ^ t]) % mod;
            }
    write((ll) f[S] * m % mod * inv2 % mod, '\n');
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...