PAT 1154. 顶点着色
原题链接
简单
作者:
YAX_AC
,
2024-11-18 14:53:34
,
所有人可见
,
阅读 2
//A proper vertex coloring is a labeling of the graph's vertices with colors
//such that no two vertices sharing the same edge have the same color.
//正确的顶点着色是用颜色标记图的顶点,这样共享同一边的两个顶点就不会有相同的颜色。
//such that使得满足…的条件,是这样…,以致如此
#include<iostream>
#include<algorithm>
#include<cstring>
#include<unordered_set>
using namespace std;
const int N = 10010;
int n,m;
int g[N][N];
int color[N];
struct edge
{
int a,b;
}e[N];
int main()
{
cin>>n>>m;
for(int i = 0; i<m; i++) cin>>e[i].a>>e[i].b;
int k; cin>>k;
while(k--)
{
for(int i = 0; i<n; i++) cin>>color[i];
int success = true;
for(int i=0;i<m;i++)
if(color[e[i].a]==color[e[i].b])
{
success=false;
break;
}
if(success)
{
unordered_set<int> S;
for(int i=0; i<n; i++) S.insert(color[i]);
printf("%d-coloring\n",S.size());
}
else cout<<"No"<<endl;
}
return 0;
}