A1154 Vertex Coloring

在这里插入图片描述

#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<queue>
#include<unordered_map>
#include<cmath>
using namespace std;
const int maxn = 10001;
int main()
{
	int n, m, t1, t2;
	cin >> n >> m;
	vector<int>v[maxn];
	int a[maxn];
	for (int i = 0; i < m; i++)
	{
		cin >> t1 >> t2;
		v[t1].push_back(t2);
		v[t2].push_back(t1);
	}
	int k; cin >> k;
	for (int j = 0; j < k; j++)
	{
		set<int>s;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
			s.insert(a[i]);
		}
		int flag = 1;
		for (int q = 0; q < n; q++)
		{
			if (flag == 0)
				break;
			for (int i = 0; i < v[q].size(); i++)
			{
				if (a[q] == a[v[q][i]])
				{
					flag = 0;
					break;
				}
			}
		}
		if (flag == 0)
			cout << "No" << endl;
		else
			cout << s.size() << "-coloring" << endl;
	}


}
posted @ 2020-08-16 17:59  _Hsiung  阅读(42)  评论(0编辑  收藏  举报