Submission #579372

# Submission time Handle Problem Language Result Execution time Memory
579372 2022-06-19T03:33:26 Z amunduzbaev Amusement Park (CEOI19_amusementpark) C++17
19 / 100
2404 ms 17264 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
//~ #define int ll

const int N = 20;
const int P = 167;
const int mod = 119 << 23 | 1;
vector<int> edges[N], qwe[N];
int used[N], is[N][N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m; cin>>n>>m;
	vector<ar<int, 2>> e(m);
	for(int i=0;i<m;i++){
		cin>>e[i][0]>>e[i][1];
		edges[e[i][0]].push_back(e[i][1]);
		edges[e[i][1]].push_back(e[i][0]);
		is[e[i][0]][e[i][1]] = 1;
	}
	
	for(int i=1;i<=n;i++) sort(edges[i].begin(), edges[i].end());
	
	vector<int> p(n);
	iota(p.begin(), p.end(), 1);
	set<int> ss;
	int res = 0;
	do{
		memset(used, 0, sizeof used);
		int cnt = 0;
		for(auto u : p){
			qwe[u].clear();
			for(auto x : edges[u]){
				if(used[x]) continue;
				qwe[u].push_back(x);
				if(!is[u][x]) cnt++;
			}
			
			used[u] = 1;
		}
		
		memset(used, 0, sizeof used);
		vector<int> t;
		function<void(int)> dfs = [&](int u){
			used[u] = 1;
			for(auto x : qwe[u]){
				if(used[x]) continue;
				dfs(x);
			}
			
			t.push_back(u);
		};
		
		for(int i=1;i<=n;i++){
			if(!used[i]) dfs(i);
		}
		
		reverse(t.begin(), t.end());
		int hh = 0;
		for(auto x : t){
			hh = (hh * 1ll * P + x) % mod;
		}
		
		if(!ss.count(hh)){
			ss.insert(hh);
			res = (res + cnt) % mod;
		}
	}while(next_permutation(p.begin(), p.end()));
	
	cout<<res<<"\n";
}
 

# 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 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 1 ms 340 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 3 ms 324 KB Output is correct
27 Correct 3 ms 212 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 14 ms 320 KB Output is correct
33 Correct 16 ms 324 KB Output is correct
34 Correct 18 ms 380 KB Output is correct
35 Correct 22 ms 472 KB Output is correct
36 Correct 23 ms 688 KB Output is correct
37 Correct 29 ms 1336 KB Output is correct
38 Correct 30 ms 2124 KB Output is correct
39 Correct 133 ms 300 KB Output is correct
40 Correct 151 ms 328 KB Output is correct
41 Correct 175 ms 340 KB Output is correct
42 Correct 187 ms 508 KB Output is correct
43 Correct 216 ms 1528 KB Output is correct
44 Correct 238 ms 2688 KB Output is correct
45 Correct 264 ms 5864 KB Output is correct
46 Correct 310 ms 11016 KB Output is correct
47 Correct 339 ms 17264 KB Output is correct
48 Correct 139 ms 320 KB Output is correct
49 Correct 166 ms 448 KB Output is correct
50 Correct 169 ms 484 KB Output is correct
51 Correct 170 ms 440 KB Output is correct
52 Correct 1396 ms 304 KB Output is correct
53 Correct 1650 ms 456 KB Output is correct
54 Correct 1885 ms 756 KB Output is correct
55 Correct 2095 ms 1928 KB Output is correct
56 Incorrect 2404 ms 8764 KB Output isn't correct
57 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 3 ms 324 KB Output is correct
27 Correct 3 ms 212 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 14 ms 320 KB Output is correct
33 Correct 16 ms 324 KB Output is correct
34 Correct 18 ms 380 KB Output is correct
35 Correct 22 ms 472 KB Output is correct
36 Correct 23 ms 688 KB Output is correct
37 Correct 29 ms 1336 KB Output is correct
38 Correct 30 ms 2124 KB Output is correct
39 Correct 133 ms 300 KB Output is correct
40 Correct 151 ms 328 KB Output is correct
41 Correct 175 ms 340 KB Output is correct
42 Correct 187 ms 508 KB Output is correct
43 Correct 216 ms 1528 KB Output is correct
44 Correct 238 ms 2688 KB Output is correct
45 Correct 264 ms 5864 KB Output is correct
46 Correct 310 ms 11016 KB Output is correct
47 Correct 339 ms 17264 KB Output is correct
48 Correct 139 ms 320 KB Output is correct
49 Correct 166 ms 448 KB Output is correct
50 Correct 169 ms 484 KB Output is correct
51 Correct 170 ms 440 KB Output is correct
52 Correct 1396 ms 304 KB Output is correct
53 Correct 1650 ms 456 KB Output is correct
54 Correct 1885 ms 756 KB Output is correct
55 Correct 2095 ms 1928 KB Output is correct
56 Incorrect 2404 ms 8764 KB Output isn't correct
57 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 3 ms 324 KB Output is correct
27 Correct 3 ms 212 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 14 ms 320 KB Output is correct
33 Correct 16 ms 324 KB Output is correct
34 Correct 18 ms 380 KB Output is correct
35 Correct 22 ms 472 KB Output is correct
36 Correct 23 ms 688 KB Output is correct
37 Correct 29 ms 1336 KB Output is correct
38 Correct 30 ms 2124 KB Output is correct
39 Correct 133 ms 300 KB Output is correct
40 Correct 151 ms 328 KB Output is correct
41 Correct 175 ms 340 KB Output is correct
42 Correct 187 ms 508 KB Output is correct
43 Correct 216 ms 1528 KB Output is correct
44 Correct 238 ms 2688 KB Output is correct
45 Correct 264 ms 5864 KB Output is correct
46 Correct 310 ms 11016 KB Output is correct
47 Correct 339 ms 17264 KB Output is correct
48 Correct 139 ms 320 KB Output is correct
49 Correct 166 ms 448 KB Output is correct
50 Correct 169 ms 484 KB Output is correct
51 Correct 170 ms 440 KB Output is correct
52 Correct 1396 ms 304 KB Output is correct
53 Correct 1650 ms 456 KB Output is correct
54 Correct 1885 ms 756 KB Output is correct
55 Correct 2095 ms 1928 KB Output is correct
56 Incorrect 2404 ms 8764 KB Output isn't correct
57 Halted 0 ms 0 KB -