原题链接
#include <iostream>
#include <set>
#include <vector>
using namespace std;
//颜色不到6个直接剔除
//存相邻的边 查看相邻点颜色是否相同
const int maxv = 501;
int v, e,k;
vector<int> color(maxv);
vector<vector<int>> vi(maxv);
bool visit[maxv] = {false};
bool f(int i)
{
for(int j = 0; j < vi[i].size(); j++)
{
if(color[i] == color[vi[i][j]]) return false;
}
return true;
}
int main()
{
int s,t;
cin >> v >> e >> k;
for(int i = 0; i < e; i++)
{
cin >> s >> t;
vi[s].push_back(t);
vi[t].push_back(s);
}
int num;
cin >> num;
while(num--)
{
set<int> s;
int flag = 1;
for(int i = 1; i <= v; i++)
{
cin >> color[i];
s.insert(color[i]);
}
if(s.size() != k) cout << "No" << endl;
else
{
for(int i = 1; i <= v; i++)
{
if(f(i) == false)
{
flag = 0;
break;
}
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
return 0;
}