Skip to content

Commit 3c66602

Browse files
committed
Euler circuits count test
1 parent 60c8e54 commit 3c66602

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

verify/linalg/euler_circs.test.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// @brief Counting Eulerian Circuits
2+
#define PROBLEM "https://judge.yosupo.jp/problem/counting_eulerian_circuits"
3+
#pragma GCC optimize("Ofast,unroll-loops")
4+
#pragma GCC target("tune=native")
5+
#include "cp-algo/math/combinatorics.hpp"
6+
#include "cp-algo/linalg/matrix.hpp"
7+
#include <bits/stdc++.h>
8+
9+
using namespace std;
10+
using namespace cp_algo::math;
11+
using namespace cp_algo::linalg;
12+
13+
const int mod = 998244353;
14+
using base = modint<mod>;
15+
16+
void solve() {
17+
int n, m;
18+
cin >> n >> m;
19+
matrix<base> a(n);
20+
int r = 0;
21+
vector<int> indeg(n), outdeg(n);
22+
for(int i = 0; i < m; i++) {
23+
int u, v;
24+
cin >> u >> v;
25+
a[u][v] -= 1;
26+
a[v][v] += 1;
27+
outdeg[u]++;
28+
indeg[v]++;
29+
r = v;
30+
}
31+
a[r][r] = fact<base>(indeg[r] - 1);
32+
for(int i = 0; i < n; i++) {
33+
if(i == r) {
34+
continue;
35+
}
36+
if(indeg[i] != outdeg[i]) {
37+
cout << 0 << "\n";
38+
return;
39+
}
40+
if(indeg[i] != 0) {
41+
a[i] *= fact<base>(indeg[i] - 1);
42+
} else {
43+
a[i][i] = 1;
44+
}
45+
a[r][i] = a[i][r] = 0;
46+
}
47+
cout << a.det() << "\n";
48+
}
49+
50+
signed main() {
51+
//freopen("input.txt", "r", stdin);
52+
ios::sync_with_stdio(0);
53+
cin.tie(0);
54+
int t = 1;
55+
// cin >> t;
56+
while(t--) {
57+
solve();
58+
}
59+
}

0 commit comments

Comments
 (0)