Submission #66972958


Source Code Expand

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

mint dp[1 << 20][20];
mint ndp[1 << 20][20];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  mint to[20][20];
  rep(_, m) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    to[u][v]++;
    to[v][u]++;
  }
  mint ans;
  for (; n >= 2; n--) {
    rep(s, 1 << (n - 1)) rep(j, n - 1) dp[s][j] = 0;
    rep(v, n - 1) dp[1 << v][v] = to[n-1][v];
    while (true) {
      bool done = true;
      rep(s, 1 << (n - 1)) rep(u, n - 1) if (mint val = dp[s][u]; val.val()) {
        done = false;
        if (popcount(0U + s) == 1) {
          ans += val * (to[u][n-1]-1);
        } else {
          ans += val * to[u][n-1];
        }
        rep(v, n - 1) if (~s >> v & 1) ndp[s | 1 << v][v] += val * to[u][v];
        // cout << s << ' ' << u << ' ' << val.val() << ' ' << ans.val() << endl;
      }
      rep(s, 1 << (n - 1)) rep(u, n - 1) dp[s][u] = ndp[s][u], ndp[s][u] = 0;
      if (done) break;
    }
    // cout << ans.val() << endl;
  }
  ans /= 2;
  cout << ans.val() << '\n';
}

Submission Info

Submission Time
Task G - Count Cycles
User Kude
Language C++ 20 (gcc 12.2)
Score 600
Code Size 1846 Byte
Status AC
Exec Time 1596 ms
Memory 167440 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 40
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 04_random4_00.txt, 04_random4_01.txt, 05_random5_00.txt, 05_random5_01.txt, 06_random6_00.txt, 06_random6_01.txt, 06_random6_02.txt, 06_random6_03.txt, 07_handmade_00.txt, 07_handmade_01.txt, 07_handmade_02.txt, 07_handmade_03.txt, 07_handmade_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 78 ms 167256 KiB
00_sample_01.txt AC 74 ms 167248 KiB
00_sample_02.txt AC 78 ms 167356 KiB
01_random_00.txt AC 364 ms 167236 KiB
01_random_01.txt AC 80 ms 167244 KiB
01_random_02.txt AC 100 ms 167300 KiB
01_random_03.txt AC 156 ms 167296 KiB
01_random_04.txt AC 1161 ms 167260 KiB
01_random_05.txt AC 1030 ms 167300 KiB
01_random_06.txt AC 1542 ms 167440 KiB
01_random_07.txt AC 1529 ms 167296 KiB
01_random_08.txt AC 1533 ms 167304 KiB
01_random_09.txt AC 1562 ms 167312 KiB
01_random_10.txt AC 1596 ms 167288 KiB
01_random_11.txt AC 1546 ms 167296 KiB
02_random2_00.txt AC 149 ms 167292 KiB
02_random2_01.txt AC 623 ms 167312 KiB
02_random2_02.txt AC 980 ms 167228 KiB
02_random2_03.txt AC 1323 ms 167236 KiB
02_random2_04.txt AC 1485 ms 167236 KiB
02_random2_05.txt AC 1502 ms 167300 KiB
02_random2_06.txt AC 1581 ms 167304 KiB
02_random2_07.txt AC 1569 ms 167440 KiB
03_random3_00.txt AC 540 ms 167236 KiB
03_random3_01.txt AC 440 ms 167304 KiB
03_random3_02.txt AC 308 ms 167296 KiB
03_random3_03.txt AC 206 ms 167292 KiB
04_random4_00.txt AC 368 ms 167236 KiB
04_random4_01.txt AC 364 ms 167308 KiB
05_random5_00.txt AC 784 ms 167304 KiB
05_random5_01.txt AC 955 ms 167236 KiB
06_random6_00.txt AC 967 ms 167296 KiB
06_random6_01.txt AC 1521 ms 167272 KiB
06_random6_02.txt AC 1558 ms 167248 KiB
06_random6_03.txt AC 1560 ms 167276 KiB
07_handmade_00.txt AC 79 ms 167304 KiB
07_handmade_01.txt AC 89 ms 167300 KiB
07_handmade_02.txt AC 139 ms 167212 KiB
07_handmade_03.txt AC 156 ms 167164 KiB
07_handmade_04.txt AC 1583 ms 167316 KiB