#include<bits/stdc++.h>
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
using namespace std;
const int MAXN = 18;
const int MOD = 998244353;
int N, M;
int adj[MAXN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
// freopen("a.in", "r", stdin); freopen("a.out", "w", stdout);
cin >> N >> M;
for(int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a] ^= MASK(b);
}
// if(N <= 6)
// {
// vector<pair<int, int>> e;
// for(int i = 0; i < N; i++)
// for(int j = 0; j < N; j++)
// if(BIT(adj[i], j))
// e.push_back(make_pair(i, j));
// int ans = 0;
// for(int mask = 0; mask < MASK(M); mask++) {
// vector<int> new_adj(N, 0);
// for(int i = 0; i < M; i++)
// if(BIT(mask, i))
// new_adj[e[i].second] ^= MASK(e[i].first);
// else
// new_adj[e[i].first] ^= MASK(e[i].second);
// vector<int> vis(N, 0);
// bool good = true;
// function<void(int)> dfs = [&](int u) {
// if(!good)
// return;
// vis[u] = 1;
// for(int i = 0; i < N; i++)
// if(BIT(new_adj[u], i) && vis[i] == 1) {
// good = false;
// return;
// }
// for(int i = 0; i < N; i++)
// if(BIT(new_adj[u], i) && vis[i] == 0) {
// dfs(i);
// if(!good)
// return;
// }
// vis[u] = 2;
// };
// for(int i = 0; i < N; i++)
// if(vis[i] == 0)
// dfs(i);
// if(good)
// (ans += __builtin_popcount(mask)) %= MOD;
// }
// cout << ans;
// }
// else
if(N <= 10) {
vector<int> p(N);
iota(begin(p), end(p), 0);
int ans = 0;
set<long long> save;
do {
vector<int> pos(N);
for(int i = 0; i < N; i++) {
pos[p[i]] = i;
}
int num = 0;
long long mask = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
if(BIT(adj[i], j)) {
if(pos[i] > pos[j])
mask ^= MASK(num);
num++;
}
}
}
if(!save.count(mask)) {
save.insert(mask);
ans += __builtin_popcountll(mask);
}
}
while(next_permutation(p.begin(), p.end()));
cout << ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
316 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
444 KB |
Output is correct |
32 |
Correct |
5 ms |
320 KB |
Output is correct |
33 |
Correct |
6 ms |
212 KB |
Output is correct |
34 |
Correct |
6 ms |
340 KB |
Output is correct |
35 |
Correct |
8 ms |
468 KB |
Output is correct |
36 |
Correct |
8 ms |
760 KB |
Output is correct |
37 |
Correct |
14 ms |
1348 KB |
Output is correct |
38 |
Correct |
12 ms |
2132 KB |
Output is correct |
39 |
Correct |
41 ms |
212 KB |
Output is correct |
40 |
Correct |
47 ms |
312 KB |
Output is correct |
41 |
Correct |
52 ms |
356 KB |
Output is correct |
42 |
Correct |
58 ms |
456 KB |
Output is correct |
43 |
Correct |
87 ms |
1580 KB |
Output is correct |
44 |
Correct |
74 ms |
2680 KB |
Output is correct |
45 |
Correct |
87 ms |
5836 KB |
Output is correct |
46 |
Correct |
105 ms |
10808 KB |
Output is correct |
47 |
Correct |
131 ms |
17236 KB |
Output is correct |
48 |
Correct |
48 ms |
212 KB |
Output is correct |
49 |
Correct |
57 ms |
488 KB |
Output is correct |
50 |
Correct |
54 ms |
496 KB |
Output is correct |
51 |
Correct |
56 ms |
508 KB |
Output is correct |
52 |
Correct |
474 ms |
300 KB |
Output is correct |
53 |
Correct |
533 ms |
324 KB |
Output is correct |
54 |
Correct |
606 ms |
564 KB |
Output is correct |
55 |
Correct |
699 ms |
1700 KB |
Output is correct |
56 |
Correct |
755 ms |
8852 KB |
Output is correct |
57 |
Correct |
858 ms |
22604 KB |
Output is correct |
58 |
Correct |
1085 ms |
48424 KB |
Output is correct |
59 |
Correct |
1286 ms |
94624 KB |
Output is correct |
60 |
Correct |
1544 ms |
170720 KB |
Output is correct |
61 |
Correct |
587 ms |
308 KB |
Output is correct |
62 |
Correct |
600 ms |
888 KB |
Output is correct |
63 |
Correct |
681 ms |
972 KB |
Output is correct |
64 |
Correct |
604 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
316 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
444 KB |
Output is correct |
32 |
Correct |
5 ms |
320 KB |
Output is correct |
33 |
Correct |
6 ms |
212 KB |
Output is correct |
34 |
Correct |
6 ms |
340 KB |
Output is correct |
35 |
Correct |
8 ms |
468 KB |
Output is correct |
36 |
Correct |
8 ms |
760 KB |
Output is correct |
37 |
Correct |
14 ms |
1348 KB |
Output is correct |
38 |
Correct |
12 ms |
2132 KB |
Output is correct |
39 |
Correct |
41 ms |
212 KB |
Output is correct |
40 |
Correct |
47 ms |
312 KB |
Output is correct |
41 |
Correct |
52 ms |
356 KB |
Output is correct |
42 |
Correct |
58 ms |
456 KB |
Output is correct |
43 |
Correct |
87 ms |
1580 KB |
Output is correct |
44 |
Correct |
74 ms |
2680 KB |
Output is correct |
45 |
Correct |
87 ms |
5836 KB |
Output is correct |
46 |
Correct |
105 ms |
10808 KB |
Output is correct |
47 |
Correct |
131 ms |
17236 KB |
Output is correct |
48 |
Correct |
48 ms |
212 KB |
Output is correct |
49 |
Correct |
57 ms |
488 KB |
Output is correct |
50 |
Correct |
54 ms |
496 KB |
Output is correct |
51 |
Correct |
56 ms |
508 KB |
Output is correct |
52 |
Correct |
474 ms |
300 KB |
Output is correct |
53 |
Correct |
533 ms |
324 KB |
Output is correct |
54 |
Correct |
606 ms |
564 KB |
Output is correct |
55 |
Correct |
699 ms |
1700 KB |
Output is correct |
56 |
Correct |
755 ms |
8852 KB |
Output is correct |
57 |
Correct |
858 ms |
22604 KB |
Output is correct |
58 |
Correct |
1085 ms |
48424 KB |
Output is correct |
59 |
Correct |
1286 ms |
94624 KB |
Output is correct |
60 |
Correct |
1544 ms |
170720 KB |
Output is correct |
61 |
Correct |
587 ms |
308 KB |
Output is correct |
62 |
Correct |
600 ms |
888 KB |
Output is correct |
63 |
Correct |
681 ms |
972 KB |
Output is correct |
64 |
Correct |
604 ms |
896 KB |
Output is correct |
65 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
316 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
444 KB |
Output is correct |
32 |
Correct |
5 ms |
320 KB |
Output is correct |
33 |
Correct |
6 ms |
212 KB |
Output is correct |
34 |
Correct |
6 ms |
340 KB |
Output is correct |
35 |
Correct |
8 ms |
468 KB |
Output is correct |
36 |
Correct |
8 ms |
760 KB |
Output is correct |
37 |
Correct |
14 ms |
1348 KB |
Output is correct |
38 |
Correct |
12 ms |
2132 KB |
Output is correct |
39 |
Correct |
41 ms |
212 KB |
Output is correct |
40 |
Correct |
47 ms |
312 KB |
Output is correct |
41 |
Correct |
52 ms |
356 KB |
Output is correct |
42 |
Correct |
58 ms |
456 KB |
Output is correct |
43 |
Correct |
87 ms |
1580 KB |
Output is correct |
44 |
Correct |
74 ms |
2680 KB |
Output is correct |
45 |
Correct |
87 ms |
5836 KB |
Output is correct |
46 |
Correct |
105 ms |
10808 KB |
Output is correct |
47 |
Correct |
131 ms |
17236 KB |
Output is correct |
48 |
Correct |
48 ms |
212 KB |
Output is correct |
49 |
Correct |
57 ms |
488 KB |
Output is correct |
50 |
Correct |
54 ms |
496 KB |
Output is correct |
51 |
Correct |
56 ms |
508 KB |
Output is correct |
52 |
Correct |
474 ms |
300 KB |
Output is correct |
53 |
Correct |
533 ms |
324 KB |
Output is correct |
54 |
Correct |
606 ms |
564 KB |
Output is correct |
55 |
Correct |
699 ms |
1700 KB |
Output is correct |
56 |
Correct |
755 ms |
8852 KB |
Output is correct |
57 |
Correct |
858 ms |
22604 KB |
Output is correct |
58 |
Correct |
1085 ms |
48424 KB |
Output is correct |
59 |
Correct |
1286 ms |
94624 KB |
Output is correct |
60 |
Correct |
1544 ms |
170720 KB |
Output is correct |
61 |
Correct |
587 ms |
308 KB |
Output is correct |
62 |
Correct |
600 ms |
888 KB |
Output is correct |
63 |
Correct |
681 ms |
972 KB |
Output is correct |
64 |
Correct |
604 ms |
896 KB |
Output is correct |
65 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |