A water problem, O (n^2) walk through the graph again to see if there are any vertex colors that are connected together.
PS: The number of colors needs to be equal to K.
really do not know such a water problem, last year when the game was not full of brain smoke ...
#include <stdio.h> #include <iostream> #include <string.h> using namespace std;
#define MAX 505 int Map[max][max];
int V[max];
int Tc[max];
int V, E, K;
void check () {int flag = 0;
for (int i = 1; I <= v; i + +) {if (flag) break;
for (int j = 0; J <= V; j + +) {if (map[i][j]==1) {if (v[i] = = V[j])
{flag = 1;
Break
}}}} if (flag) printf ("no\n");
else printf ("yes\n");
} int main () {scanf ("%d%d%d", &v, &e, &k);
memset (map, 0, sizeof (map));
int A, B;
for (int i = 0; i < e; i + +) {scanf ("%d%d", &a, &b);
MAP[A][B] = 1;
Map[b][a] = 1;
} int flag, NNN;
scanf ("%d", &nnn);
for (int i = 0; i < nnn; i + +) {memset (TC, 0, sizeof (TC));
Flag = 0; for (int j = 1; J <= V ;
J + +) {scanf ("%d", &v[j]);
if (tc[v[j]] = = 0) {Tc[v[j]] = 1;
Flag + +;
}} if (flag! = k) printf ("no\n");
else {check ();
}} return 0;
}