# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
17297 | gs14004 | 지도 색칠하기 (GA3_map) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
struct disj{
int pa[42];
void init(int n){
for(int i=1; i<=n; i++) pa[i] = i;
}
int find(int x){
return pa[x] = (pa[x] == x ? x : find(pa[x]));
}
bool uni(int p, int q){
p = find(p);
q = find(q);
if(p == q) return 0;
pa[q] = p;
return 1;
}
}disj;
int n, m;
int s[200], e[200];
int main(){
lint sum = 0;
scanf("%d %d",&n,&m);
for(int i=0; i<m; i++){
scanf("%d %d",&s[i],&e[i]);
}
for(int i=0; i<(1<<(n-1)); i++){
disj.init(2*n);
bool bad = 0;
for(int j=0; j<m; j++){
if(((i >> (s[j] - 1)) & 1) == ((i >> (e[j] - 1)) & 1)){
disj.uni(s[j], e[j] + n);
disj.uni(e[j], s[j] + n);
if(disj.find(s[j]) == disj.find(s[j] + n)){
bad = 1;
break;
}
}
}
if(bad) continue;
int cnt = 0;
for(int i=1; i<=2*n; i++){
if(disj.uni(i, 1)){
cnt++;
}
}
cnt = (cnt + 1) / 2;
sum += (2 << cnt);
}
printf("%lld",sum);
}