PAT 1154

这道题是水题

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
using namespace std;
int main()
{
	int n = 0, m = 0;
	cin >> n >> m;
	vector<vector<int> > data(n+2);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d%d",&a,&b);
		data[a].push_back(b);
		data[b].push_back(a);
	}
	int h;
	cin >> h;
	for (int i = 0; i < h; i++)
	{
		set<int> sp; map<int,int> p;
		for (int j = 0; j < n; j++)  //输入每个点的颜色
		{
			int y;
			scanf("%d",&y); sp.insert(y);
			p[j] = y;
		}
		bool is = true;
		for (int k = 0; k < n; k++)  //检查每一个节点是否有颜色相同的节点
		{
			for (int ij = 0; ij < data[k].size(); ij++)
			{
				int dian = data[k][ij];
				int x1 = p[k]; int x2 = p[data[k][ij]];
				if (p[k] == p[data[k][ij]]){
					is = false; break;
				}
			}
			if (is == false)break;
		}
		if (is == false)printf("No");
		else printf("%d-coloring", sp.size());
		if (i != h - 1)printf("\n");
	}


	return 0;
}

 

posted @ 2018-12-10 19:58  代码拯救世界可以吗  阅读(201)  评论(0编辑  收藏  举报