The graph coloring problem is a well-known NP-complete problem. Given the graph, ask if you can assign a color to each vertex in V with a k color, so that no two adjacent vertices have the same color.
But the question is not to solve this coloring problem, but for a given color assignment, please decide if this is a solution to the graph coloring problem. Input Format:
The input gives 3 integers in the first line (0), E (≥), and K (0), respectively, the number of vertices, sides, and colors of the graph. Vertices and colors are numbered from 1 to v. Then the E line, each row gives the number of the two endpoints of an edge. After the information in the graph is given, a positive integer n (≤) is given, which is the number of color assignment schemes to be checked. Then n rows, each row is given the color of the V vertex (the number I represents the color of the vertex i), and the numbers are separated by a space. The topic guarantees that the given graph is valid (i.e., there is no self-loop and heavy-side). output Format:
For each color allocation scheme, if it is a solution to the graph coloring problem output Yes, otherwise output no, one row per sentence. Input Sample:
6 8 3
2 1
1 3
4 6 2
5 2
4
5 4
5 6
3 6
4
1 2 3 3 1 2
4 5 6 6 4 5
1 2 3 4 5 6
2 3 4 2 3 4
Sample output:
yes Yes No no
#include <bits/stdc++.h> using namespace std;
Vector<int > bian[501];
int main () {int v,n,c;
cin>>v>>n>>c;
int A, B;
for (int i=0;i<n;i++) {cin>>a>>b;
Bian[a].push_back (b);
Bian[b].push_back (a);
} int z,xixi[501]={0};
BOOL Panduan;
cin>>z;
set<int>s;
while (z--) {//memset (xixi,0,sizeof (Xixi));
S.clear ();
Panduan=true;
for (int i=1;i<=v;i++) {cin>>xixi[i];
S.insert (Xixi[i]);
}//cout<< "size=" <<s.size () <<endl;
if (S.size ()!=c) Panduan=false;
cout<< "1111111111";
for (int. i=1;i<=v&&panduan;i++) {for (int j=0;j<bian[i].size () &&panduan;j++)
{if (Xixi[i]==xixi[bian[i][j]]) Panduan=false;
}} if (Panduan) cout<< "Yes" <<endl;
else cout<< "No" <<endl;
} return 0;
}