#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int> g[N];
struct DSU {
vector<int> e;
DSU(int n) {
e=vector<int>(n+1, -1);
}
int get(int x) {
if(e[x] < 0)return x;
return e[x] = get(e[x]);
}
int sz(int x) {
return -e[get(x)];
}
bool unite(int a, int b) {
a=get(a),b=get(b);
if(a == b)return false;
if(-e[a] > -e[b]) {
swap(a,b);
}
e[b]+=e[a];
e[a] = b;
return true;
}
};
int main () {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for(int i = 0;i<m;i++) {
int u, v;
cin >> u >> v;
u--,v--;
g[u].push_back(v);
}
if(n <= 20) {
int ans=0;
for(int mask = 1;mask<(1<<n);mask++) {
DSU d(n);
int cnt=0;
int f=-1, sz=0;
for(int j = 0;j<n;j++) {
if(mask&(1<<j)) {
sz++;
f=j;
for(int to:g[j]){
if(mask&(1<<to)) {
d.unite(to, j);
cnt++;
}
}
}
}
if(d.sz(f) == sz and cnt==sz-1){
ans++;
}
}
cout << ans <<"\n";
}
else {
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2804 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
99 ms |
2652 KB |
Output is correct |
9 |
Correct |
96 ms |
2652 KB |
Output is correct |
10 |
Correct |
101 ms |
2652 KB |
Output is correct |
11 |
Correct |
111 ms |
2784 KB |
Output is correct |
12 |
Correct |
48 ms |
2652 KB |
Output is correct |
13 |
Correct |
101 ms |
2648 KB |
Output is correct |
14 |
Correct |
49 ms |
2652 KB |
Output is correct |
15 |
Correct |
50 ms |
2652 KB |
Output is correct |
16 |
Correct |
105 ms |
2780 KB |
Output is correct |
17 |
Correct |
47 ms |
2652 KB |
Output is correct |
18 |
Correct |
50 ms |
2648 KB |
Output is correct |
19 |
Correct |
51 ms |
2652 KB |
Output is correct |
20 |
Correct |
105 ms |
2652 KB |
Output is correct |
21 |
Correct |
119 ms |
2652 KB |
Output is correct |
22 |
Correct |
50 ms |
2652 KB |
Output is correct |
23 |
Correct |
96 ms |
2780 KB |
Output is correct |
24 |
Correct |
46 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
4 ms |
2652 KB |
Output is correct |
29 |
Correct |
48 ms |
2624 KB |
Output is correct |
30 |
Correct |
98 ms |
2780 KB |
Output is correct |
31 |
Correct |
53 ms |
2652 KB |
Output is correct |
32 |
Correct |
59 ms |
2648 KB |
Output is correct |
33 |
Correct |
52 ms |
2648 KB |
Output is correct |
34 |
Correct |
97 ms |
2652 KB |
Output is correct |
35 |
Correct |
103 ms |
2652 KB |
Output is correct |
36 |
Correct |
114 ms |
2648 KB |
Output is correct |
37 |
Correct |
108 ms |
2652 KB |
Output is correct |
38 |
Correct |
101 ms |
2648 KB |
Output is correct |
39 |
Correct |
110 ms |
2652 KB |
Output is correct |
40 |
Correct |
92 ms |
2784 KB |
Output is correct |
41 |
Correct |
94 ms |
2648 KB |
Output is correct |
42 |
Correct |
45 ms |
2784 KB |
Output is correct |
43 |
Correct |
42 ms |
2784 KB |
Output is correct |
44 |
Correct |
91 ms |
2648 KB |
Output is correct |
45 |
Correct |
97 ms |
2652 KB |
Output is correct |
46 |
Correct |
92 ms |
2652 KB |
Output is correct |
47 |
Correct |
89 ms |
2648 KB |
Output is correct |
48 |
Correct |
92 ms |
2652 KB |
Output is correct |
49 |
Correct |
92 ms |
2652 KB |
Output is correct |
50 |
Correct |
98 ms |
2652 KB |
Output is correct |
51 |
Correct |
95 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2804 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
99 ms |
2652 KB |
Output is correct |
9 |
Correct |
96 ms |
2652 KB |
Output is correct |
10 |
Correct |
101 ms |
2652 KB |
Output is correct |
11 |
Correct |
111 ms |
2784 KB |
Output is correct |
12 |
Correct |
48 ms |
2652 KB |
Output is correct |
13 |
Correct |
101 ms |
2648 KB |
Output is correct |
14 |
Correct |
49 ms |
2652 KB |
Output is correct |
15 |
Correct |
50 ms |
2652 KB |
Output is correct |
16 |
Correct |
105 ms |
2780 KB |
Output is correct |
17 |
Correct |
47 ms |
2652 KB |
Output is correct |
18 |
Correct |
50 ms |
2648 KB |
Output is correct |
19 |
Correct |
51 ms |
2652 KB |
Output is correct |
20 |
Correct |
105 ms |
2652 KB |
Output is correct |
21 |
Correct |
119 ms |
2652 KB |
Output is correct |
22 |
Correct |
50 ms |
2652 KB |
Output is correct |
23 |
Correct |
96 ms |
2780 KB |
Output is correct |
24 |
Correct |
46 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
4 ms |
2652 KB |
Output is correct |
29 |
Correct |
48 ms |
2624 KB |
Output is correct |
30 |
Correct |
98 ms |
2780 KB |
Output is correct |
31 |
Correct |
53 ms |
2652 KB |
Output is correct |
32 |
Correct |
59 ms |
2648 KB |
Output is correct |
33 |
Correct |
52 ms |
2648 KB |
Output is correct |
34 |
Correct |
97 ms |
2652 KB |
Output is correct |
35 |
Correct |
103 ms |
2652 KB |
Output is correct |
36 |
Correct |
114 ms |
2648 KB |
Output is correct |
37 |
Correct |
108 ms |
2652 KB |
Output is correct |
38 |
Correct |
101 ms |
2648 KB |
Output is correct |
39 |
Correct |
110 ms |
2652 KB |
Output is correct |
40 |
Correct |
92 ms |
2784 KB |
Output is correct |
41 |
Correct |
94 ms |
2648 KB |
Output is correct |
42 |
Correct |
45 ms |
2784 KB |
Output is correct |
43 |
Correct |
42 ms |
2784 KB |
Output is correct |
44 |
Correct |
91 ms |
2648 KB |
Output is correct |
45 |
Correct |
97 ms |
2652 KB |
Output is correct |
46 |
Correct |
92 ms |
2652 KB |
Output is correct |
47 |
Correct |
89 ms |
2648 KB |
Output is correct |
48 |
Correct |
92 ms |
2652 KB |
Output is correct |
49 |
Correct |
92 ms |
2652 KB |
Output is correct |
50 |
Correct |
98 ms |
2652 KB |
Output is correct |
51 |
Correct |
95 ms |
2648 KB |
Output is correct |
52 |
Incorrect |
2 ms |
2904 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2804 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
99 ms |
2652 KB |
Output is correct |
9 |
Correct |
96 ms |
2652 KB |
Output is correct |
10 |
Correct |
101 ms |
2652 KB |
Output is correct |
11 |
Correct |
111 ms |
2784 KB |
Output is correct |
12 |
Correct |
48 ms |
2652 KB |
Output is correct |
13 |
Correct |
101 ms |
2648 KB |
Output is correct |
14 |
Correct |
49 ms |
2652 KB |
Output is correct |
15 |
Correct |
50 ms |
2652 KB |
Output is correct |
16 |
Correct |
105 ms |
2780 KB |
Output is correct |
17 |
Correct |
47 ms |
2652 KB |
Output is correct |
18 |
Correct |
50 ms |
2648 KB |
Output is correct |
19 |
Correct |
51 ms |
2652 KB |
Output is correct |
20 |
Correct |
105 ms |
2652 KB |
Output is correct |
21 |
Correct |
119 ms |
2652 KB |
Output is correct |
22 |
Correct |
50 ms |
2652 KB |
Output is correct |
23 |
Correct |
96 ms |
2780 KB |
Output is correct |
24 |
Correct |
46 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
4 ms |
2652 KB |
Output is correct |
29 |
Correct |
48 ms |
2624 KB |
Output is correct |
30 |
Correct |
98 ms |
2780 KB |
Output is correct |
31 |
Correct |
53 ms |
2652 KB |
Output is correct |
32 |
Correct |
59 ms |
2648 KB |
Output is correct |
33 |
Correct |
52 ms |
2648 KB |
Output is correct |
34 |
Correct |
97 ms |
2652 KB |
Output is correct |
35 |
Correct |
103 ms |
2652 KB |
Output is correct |
36 |
Correct |
114 ms |
2648 KB |
Output is correct |
37 |
Correct |
108 ms |
2652 KB |
Output is correct |
38 |
Correct |
101 ms |
2648 KB |
Output is correct |
39 |
Correct |
110 ms |
2652 KB |
Output is correct |
40 |
Correct |
92 ms |
2784 KB |
Output is correct |
41 |
Correct |
94 ms |
2648 KB |
Output is correct |
42 |
Correct |
45 ms |
2784 KB |
Output is correct |
43 |
Correct |
42 ms |
2784 KB |
Output is correct |
44 |
Correct |
91 ms |
2648 KB |
Output is correct |
45 |
Correct |
97 ms |
2652 KB |
Output is correct |
46 |
Correct |
92 ms |
2652 KB |
Output is correct |
47 |
Correct |
89 ms |
2648 KB |
Output is correct |
48 |
Correct |
92 ms |
2652 KB |
Output is correct |
49 |
Correct |
92 ms |
2652 KB |
Output is correct |
50 |
Correct |
98 ms |
2652 KB |
Output is correct |
51 |
Correct |
95 ms |
2648 KB |
Output is correct |
52 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |