File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments