zoukankan      html  css  js  c++  java
  • 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("
    ");
    	}
    
    
    	return 0;
    }
    
  • 相关阅读:
    网上订餐系统后台代码bug记录与解决
    vector二维数组
    力扣-树-练习题(一)
    优先队列

    并查集
    C++进制转换函数
    平衡二叉树(AVL树)定义与基本操作
    二叉查找树练习题
    树的遍历
  • 原文地址:https://www.cnblogs.com/luoshiyong/p/10098726.html
Copyright © 2011-2022 走看看