对V个顶点,E条边的图,用n种颜色进行涂色,要求共边的两点颜色不相同,一共有多少种涂法?
#include<iostream>
#include<cstring>
using namespace std;
int G[111][111];
int x[111];
int V, E, n, count = 0;
bool judge(int t, int i)
{
for(int k= 1; k <= V; k++)
if(G[k][t] == 1 && x[k] == i)
return false;
return true;
}
void dfs(int t){
if(t > V)
{
count++;
/*for(int i = 1; i <= V; i++)
cout << x[i] << " ";
cout << endl; */
return;
}
for(int i = 1; i <= n; i++)
{
if(judge(t, i))
{
x[t] = i;
dfs(t+1);
x[t] = 0;
}
}
}
int main(){
cin >> V >> E >> n;
for(int i = 0; i < E; i++)
{
int a, b;
cin >> a >> b;
G[a][b] = G[b][a] = 1;
}
dfs(1);
cout << count << endl;
return 0;
}