【2019暑期】【PAT甲级】1154 Vertex Coloring (25 分)

48 篇文章 0 订阅

这道题的题意没看懂,看了解析才勉强懂
题意就是先输入的这些是一个边的两个端点
第二个输入的是每个点的颜色
要做的就是判断每条边的两个点的颜色是否相同,不相同就输出一共有的颜色种类

用set进行颜色的筛选
用结构体存储节点,直接判断

错误的点再记得区分哪里用m,n,不要混

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <cmath>
#include <map> 
#include <set>
using namespace std;

int m,n,k;
struct node{
	int v1;
	int v2;
}; 
	
int main(){
	
	cin >> n >> m;
	vector<node> no(m);
	for(int i=0; i<m; i++){
		//cin >> no[i].v1 >> no[i].v2;
		scanf("%d %d", &no[i].v1, &no[i].v2);
	}
	cin >> k;
	while(k--){
		set<int> ans;
		int a[10009] = {0};
		bool key = true;
		for(int j=0; j<n; j++){
			//cin >> a[j];
			scanf("%d",&a[j]);
			ans.insert(a[j]);
		}
		for(int l=0; l<m; l++){
			if(a[no[l].v1] == a[no[l].v2]){
				key = false;
				break;
			}
		}
		if(key)
			cout << ans.size() << "-coloring" << endl;
		else
			cout << "No" << endl;
		ans.clear();
	}
	
	return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值