#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 12, MAXM = 200;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, m;
int from[MAXM], to[MAXM];
void read()
{
cin >> n >> m;
for (int i = 1; i <= m; ++ i)
cin >> from[i] >> to[i];
}
int order[MAXN], used[MAXN], visited[MAXN], in_cycle[MAXN]; /// na koq poziciq e i
int ans = 0, imp = 0;
const long long mod = 998244353;
set < vector < int > > mp;
vector < int > g[MAXN];
void dfs(int beg)
{
visited[beg] = 1;
in_cycle[beg] = 1;
for (auto nb: g[beg])
{
if(!visited[nb])dfs(nb);
else if(in_cycle[nb])imp = 1;
}
in_cycle[beg] = 0;
}
void check()
{
for (int i = 1; i <= n; ++ i)
{
g[i].clear();
visited[i] = 0;
in_cycle[i] = 0;
}
vector < int > u;
int cnt = 0;
for (int i = 1; i <= m; ++ i)
{
if(order[from[i]] > order[to[i]])
{
u.push_back(0);
g[from[i]].push_back(to[i]);
}
else
{
cnt ++;
u.push_back(1);
g[to[i]].push_back(from[i]);
}
}
if(mp.find(u) != mp.end())return;
mp.insert(u);
imp = 0;
for (int i = 1; i <= n && (!imp); ++ i)
{
if(visited[order[i]])continue;
dfs(visited[order[i]]);
}
if(imp)return;
ans += cnt;
//ans %= mod;
}
void gen(int pos)
{
if(pos > n)
{
check();
return;
}
for (int i = 1; i <= n; ++ i)
{
if(used[i])continue;
order[pos] = i;
used[i] = 1;
gen(pos+1);
used[i] = 0;
}
}
int main()
{
speed();
read();
gen(1);
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
3 ms |
592 KB |
Output is correct |
30 |
Correct |
4 ms |
848 KB |
Output is correct |
31 |
Correct |
6 ms |
1104 KB |
Output is correct |
32 |
Correct |
6 ms |
336 KB |
Output is correct |
33 |
Correct |
8 ms |
336 KB |
Output is correct |
34 |
Correct |
14 ms |
612 KB |
Output is correct |
35 |
Correct |
17 ms |
832 KB |
Output is correct |
36 |
Correct |
29 ms |
1904 KB |
Output is correct |
37 |
Correct |
47 ms |
4392 KB |
Output is correct |
38 |
Correct |
66 ms |
7780 KB |
Output is correct |
39 |
Correct |
46 ms |
336 KB |
Output is correct |
40 |
Correct |
68 ms |
472 KB |
Output is correct |
41 |
Correct |
99 ms |
556 KB |
Output is correct |
42 |
Correct |
116 ms |
1096 KB |
Output is correct |
43 |
Correct |
173 ms |
4788 KB |
Output is correct |
44 |
Correct |
290 ms |
9432 KB |
Output is correct |
45 |
Correct |
329 ms |
22600 KB |
Output is correct |
46 |
Correct |
461 ms |
46076 KB |
Output is correct |
47 |
Correct |
557 ms |
79868 KB |
Output is correct |
48 |
Correct |
64 ms |
336 KB |
Output is correct |
49 |
Correct |
110 ms |
840 KB |
Output is correct |
50 |
Correct |
106 ms |
812 KB |
Output is correct |
51 |
Correct |
146 ms |
840 KB |
Output is correct |
52 |
Correct |
570 ms |
336 KB |
Output is correct |
53 |
Correct |
860 ms |
336 KB |
Output is correct |
54 |
Correct |
1207 ms |
1292 KB |
Output is correct |
55 |
Correct |
1659 ms |
5476 KB |
Output is correct |
56 |
Correct |
2259 ms |
31508 KB |
Output is correct |
57 |
Correct |
2968 ms |
89756 KB |
Output is correct |
58 |
Execution timed out |
3059 ms |
185416 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
3 ms |
592 KB |
Output is correct |
30 |
Correct |
4 ms |
848 KB |
Output is correct |
31 |
Correct |
6 ms |
1104 KB |
Output is correct |
32 |
Correct |
6 ms |
336 KB |
Output is correct |
33 |
Correct |
8 ms |
336 KB |
Output is correct |
34 |
Correct |
14 ms |
612 KB |
Output is correct |
35 |
Correct |
17 ms |
832 KB |
Output is correct |
36 |
Correct |
29 ms |
1904 KB |
Output is correct |
37 |
Correct |
47 ms |
4392 KB |
Output is correct |
38 |
Correct |
66 ms |
7780 KB |
Output is correct |
39 |
Correct |
46 ms |
336 KB |
Output is correct |
40 |
Correct |
68 ms |
472 KB |
Output is correct |
41 |
Correct |
99 ms |
556 KB |
Output is correct |
42 |
Correct |
116 ms |
1096 KB |
Output is correct |
43 |
Correct |
173 ms |
4788 KB |
Output is correct |
44 |
Correct |
290 ms |
9432 KB |
Output is correct |
45 |
Correct |
329 ms |
22600 KB |
Output is correct |
46 |
Correct |
461 ms |
46076 KB |
Output is correct |
47 |
Correct |
557 ms |
79868 KB |
Output is correct |
48 |
Correct |
64 ms |
336 KB |
Output is correct |
49 |
Correct |
110 ms |
840 KB |
Output is correct |
50 |
Correct |
106 ms |
812 KB |
Output is correct |
51 |
Correct |
146 ms |
840 KB |
Output is correct |
52 |
Correct |
570 ms |
336 KB |
Output is correct |
53 |
Correct |
860 ms |
336 KB |
Output is correct |
54 |
Correct |
1207 ms |
1292 KB |
Output is correct |
55 |
Correct |
1659 ms |
5476 KB |
Output is correct |
56 |
Correct |
2259 ms |
31508 KB |
Output is correct |
57 |
Correct |
2968 ms |
89756 KB |
Output is correct |
58 |
Execution timed out |
3059 ms |
185416 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
3 ms |
592 KB |
Output is correct |
30 |
Correct |
4 ms |
848 KB |
Output is correct |
31 |
Correct |
6 ms |
1104 KB |
Output is correct |
32 |
Correct |
6 ms |
336 KB |
Output is correct |
33 |
Correct |
8 ms |
336 KB |
Output is correct |
34 |
Correct |
14 ms |
612 KB |
Output is correct |
35 |
Correct |
17 ms |
832 KB |
Output is correct |
36 |
Correct |
29 ms |
1904 KB |
Output is correct |
37 |
Correct |
47 ms |
4392 KB |
Output is correct |
38 |
Correct |
66 ms |
7780 KB |
Output is correct |
39 |
Correct |
46 ms |
336 KB |
Output is correct |
40 |
Correct |
68 ms |
472 KB |
Output is correct |
41 |
Correct |
99 ms |
556 KB |
Output is correct |
42 |
Correct |
116 ms |
1096 KB |
Output is correct |
43 |
Correct |
173 ms |
4788 KB |
Output is correct |
44 |
Correct |
290 ms |
9432 KB |
Output is correct |
45 |
Correct |
329 ms |
22600 KB |
Output is correct |
46 |
Correct |
461 ms |
46076 KB |
Output is correct |
47 |
Correct |
557 ms |
79868 KB |
Output is correct |
48 |
Correct |
64 ms |
336 KB |
Output is correct |
49 |
Correct |
110 ms |
840 KB |
Output is correct |
50 |
Correct |
106 ms |
812 KB |
Output is correct |
51 |
Correct |
146 ms |
840 KB |
Output is correct |
52 |
Correct |
570 ms |
336 KB |
Output is correct |
53 |
Correct |
860 ms |
336 KB |
Output is correct |
54 |
Correct |
1207 ms |
1292 KB |
Output is correct |
55 |
Correct |
1659 ms |
5476 KB |
Output is correct |
56 |
Correct |
2259 ms |
31508 KB |
Output is correct |
57 |
Correct |
2968 ms |
89756 KB |
Output is correct |
58 |
Execution timed out |
3059 ms |
185416 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |