Submission #1089789

#TimeUsernameProblemLanguageResultExecution timeMemory
1089789juicyAmusement Park (CEOI19_amusementpark)C++17
100 / 100
1459 ms2644 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  const int M = 998244353;

  auto add = [&](int &x, int y) {
    if ((x += y) >= M) {
      x -= M;
    }
    if (x < 0) {
      x += M;
    }
  };
  auto pw = [&](int a, int b) {
    int res = 1;
    for (; b; a = (long long) a * a % M, b /= 2) {
      if (b & 1) {
        res = (long long) res * a % M;
      }
    }
    return res;
  };
  int n, m; cin >> n >> m;
  vector a(n, vector<bool>(n));
  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v; --u, --v;
    a[u][v] = a[v][u] = 1;
  }
  vector<int> ind(1 << n, 1);
  for (int i = 0; i < 1 << n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i >> j & 1) {
        for (int k = j + 1; k < n; ++k) {
          if (i >> k & 1) {
            ind[i] &= !a[j][k];
          }
        }
      }
    }
  }
  vector<int> cnt(1 << n);
  cnt[0] = 1;
  for (int i = 1; i < 1 << n; ++i) {
    for (int j = i; j; j = (j - 1) & i) {
      if (ind[j]) {
        if (__builtin_popcount(j) & 1) {
          add(cnt[i], cnt[i ^ j]);
        } else {
          add(cnt[i], -cnt[i ^ j]);
        }
      }
    }
  }
  cout << (long long) cnt.back() * m % M * pw(2, M - 2) % M;
  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...