リンクタイトル:https://www.luogu.com.cn/problem/P2819
タイトル効果:図の数mを着色するために求めています。
問題解決のアイデア:n個の点が競合することなく染めている場合は、1色の検索数は、ポイントソリューションを列挙しませんでした。
次のようにコードは次のとおりです。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
vector<int> g[maxn];
int n, k, m, color[maxn], ans;
void dfs(int u) {
if (u > n) {
ans ++;
return;
}
int sz = g[u].size();
for (int c = 1; c <= m; c ++) {
bool flag = true;
for (int i = 0; i < sz; i ++) {
int v = g[u][i];
if (color[v] == c) {
flag = false;
break;
}
}
if (flag) {
color[u] = c;
dfs(u+1);
color[u] = 0;
}
}
}
int main() {
cin >> n >> k >> m;
while (k --) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1);
cout << ans << endl;
return 0;
}