답안 #17306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
17306 2015-11-19T12:09:38 Z gs14004 지도 색칠하기 (GA3_map) C++14
0 / 120
585 ms 1084 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(!col[i] && 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Correct 0 ms 1084 KB Output is correct
4 Correct 0 ms 1084 KB Output is correct
5 Incorrect 0 ms 1084 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Correct 0 ms 1084 KB Output is correct
4 Correct 0 ms 1084 KB Output is correct
5 Incorrect 0 ms 1084 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Correct 2 ms 1084 KB Output is correct
4 Correct 2 ms 1084 KB Output is correct
5 Correct 5 ms 1084 KB Output is correct
6 Incorrect 8 ms 1084 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1084 KB Output is correct
2 Correct 63 ms 1084 KB Output is correct
3 Correct 28 ms 1084 KB Output is correct
4 Correct 27 ms 1084 KB Output is correct
5 Correct 63 ms 1084 KB Output is correct
6 Incorrect 48 ms 1084 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 421 ms 1084 KB Output is correct
2 Correct 377 ms 1084 KB Output is correct
3 Correct 379 ms 1084 KB Output is correct
4 Correct 361 ms 1084 KB Output is correct
5 Correct 446 ms 1084 KB Output is correct
6 Incorrect 585 ms 1084 KB Output isn't correct
7 Halted 0 ms 0 KB -