Files
python/TangDou/Mkx/202412C1/8741_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

38 lines
1013 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 15;
int n, ans, color[N];
// N个公共边
struct Node {
int x, y;
} a[N];
void dfs(int u) {
if (u > 5) { // 判断
bool flag = true;
// 检查此时的安排是不是合理
for (int i = 1; i <= n; i++) { // 遍历每个公共边
if (color[a[i].x] == color[a[i].y]) { // 如果两个区域的颜色相同,则返回
flag = false;
break;
}
}
if (flag) ans++; // 找到了一个新方案
return;
}
// 枚举方案
for (int i = 1; i <= 4; i++) {
color[u] = i; // u这个区域放i这个颜色
dfs(u + 1); // 走到下一个区域面前
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; // 区域x与区域y之间存在公共边
// 开始搜索
dfs(1);
// 输出结果
cout << ans << endl;
return 0;
}