Submission #793412

# Submission time Handle Problem Language Result Execution time Memory
793412 2023-07-25T19:41:33 Z Sputnik123 지도 색칠하기 (GA3_map) C++14
120 / 120
662 ms 340 KB
#include <algorithm>
using namespace std;
 
bool adj[20][20];
int col[20];
 
int bits, n;
bool bad;
 
void dfs(int x, int p){
	if(col[x]){
		bad |= (col[x] != p);
		return;
	}
	col[x] = p;
	for(int i=0; i<n; i++){
		if(adj[x][i] && (bits >> i) % 2 == (bits >> x) % 2){
			dfs(i, 3-p);
		}
	}
}
 
long long NumberOfMaps (int N, int M, int *A, int *B){
	n = N;
	for(int i=0; i<M; i++){
		adj[A[i]-1][B[i]-1] = 1;
		adj[B[i]-1][A[i]-1] = 1;
	}
	long long sum = 0;
	for(int i=0; i<(1<<(N-1)); i++){
		fill(col, col + N, 0);
		bits = i;
		bad = 0;
		int cnt = 0;
		for(int i=0; i<N; i++){
			if(col[i]) continue;
			dfs(i, 1);
			if(bad) break;
			cnt++;
		}
		if(bad) continue;
		sum += (2 << cnt);
	}
	return sum;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 284 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 288 KB Output is correct
10 Correct 0 ms 284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 284 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 284 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 2 ms 340 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 288 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 288 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 288 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 4 ms 288 KB Output is correct
6 Correct 3 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 4 ms 212 KB Output is correct
11 Correct 4 ms 288 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 5 ms 212 KB Output is correct
14 Correct 4 ms 284 KB Output is correct
15 Correct 4 ms 212 KB Output is correct
16 Correct 6 ms 212 KB Output is correct
17 Correct 3 ms 212 KB Output is correct
18 Correct 5 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 3 ms 284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 212 KB Output is correct
2 Correct 23 ms 212 KB Output is correct
3 Correct 11 ms 292 KB Output is correct
4 Correct 16 ms 284 KB Output is correct
5 Correct 33 ms 212 KB Output is correct
6 Correct 14 ms 288 KB Output is correct
7 Correct 30 ms 268 KB Output is correct
8 Correct 16 ms 212 KB Output is correct
9 Correct 32 ms 212 KB Output is correct
10 Correct 29 ms 212 KB Output is correct
11 Correct 21 ms 212 KB Output is correct
12 Correct 21 ms 288 KB Output is correct
13 Correct 50 ms 260 KB Output is correct
14 Correct 47 ms 272 KB Output is correct
15 Correct 20 ms 212 KB Output is correct
16 Correct 62 ms 212 KB Output is correct
17 Correct 68 ms 212 KB Output is correct
18 Correct 21 ms 288 KB Output is correct
19 Correct 46 ms 212 KB Output is correct
20 Correct 20 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 268 KB Output is correct
2 Correct 106 ms 212 KB Output is correct
3 Correct 115 ms 264 KB Output is correct
4 Correct 115 ms 212 KB Output is correct
5 Correct 141 ms 264 KB Output is correct
6 Correct 149 ms 268 KB Output is correct
7 Correct 126 ms 268 KB Output is correct
8 Correct 124 ms 212 KB Output is correct
9 Correct 158 ms 268 KB Output is correct
10 Correct 115 ms 268 KB Output is correct
11 Correct 236 ms 268 KB Output is correct
12 Correct 229 ms 268 KB Output is correct
13 Correct 223 ms 268 KB Output is correct
14 Correct 208 ms 212 KB Output is correct
15 Correct 230 ms 272 KB Output is correct
16 Correct 300 ms 272 KB Output is correct
17 Correct 313 ms 264 KB Output is correct
18 Correct 205 ms 264 KB Output is correct
19 Correct 216 ms 268 KB Output is correct
20 Correct 208 ms 212 KB Output is correct
21 Correct 662 ms 284 KB Output is correct
22 Correct 655 ms 272 KB Output is correct
23 Correct 433 ms 268 KB Output is correct
24 Correct 489 ms 212 KB Output is correct
25 Correct 486 ms 268 KB Output is correct
26 Correct 313 ms 264 KB Output is correct
27 Correct 327 ms 276 KB Output is correct
28 Correct 327 ms 268 KB Output is correct
29 Correct 312 ms 264 KB Output is correct
30 Correct 321 ms 264 KB Output is correct