PAT Advanced 1154 Vertex Coloring (25 分)
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. A coloring using at most k colors is called a (proper) k-coloring.
Now you are supposed to tell if a given coloring is a proper k-coloring.
Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers N and M (both no more than 1), being the total numbers of vertices and edges, respectively. Then M lines follow, each describes an edge by giving the indices (from 0 to N−1) of the two ends of the edge.
After the graph, a positive integer K (≤ 100) is given, which is the number of colorings you are supposed to check. Then K lines follow, each contains N colors which are represented by non-negative integers in the range of int. The i-th color is the color of the i-th vertex.
Output Specification:
For each coloring, print in a line k-coloring if it is a proper k-coloring for some positive k, or No if not.
Sample Input:
10 11
8 7
6 8
4 5
8 4
8 1
1 2
1 4
9 8
9 1
1 0
2 4
4
0 1 0 1 4 1 0 1 3 0
0 1 0 1 4 1 0 1 0 0
8 1 0 1 4 1 0 5 3 0
1 2 3 4 5 6 7 8 8 9
Sample Output:
4-coloring
No
6-coloring
No
#include <iostream>
#include <unordered_set>
#include <algorithm>
using namespace std; int main()
{
int vertx_num,edge_num,x,y;
cin>>vertx_num>>edge_num;
pair<int,int> p[edge_num];
for(int i=;i<edge_num;i++)
cin>>p[i].first>>p[i].second;
int test;cin>>test;int color[vertx_num];
while(test--){
bool no=false;unordered_set<int> s;
for(int i=;i<vertx_num;i++){
cin>>color[i];
s.insert(color[i]);
}
for(int i=;i<edge_num;i++){
if(color[p[i].first]==color[p[i].second]){
cout<<"No"<<endl;
no=true;
break;
}
}
if(!no) cout<<s.size()<<"-coloring"<<endl;
}
system("pause");
return ;
}
PAT Advanced 1154 Vertex Coloring (25 分)的更多相关文章
- PAT Advanced 1154 Vertex Coloring (25) [set,hash]
题目 A proper vertex coloring is a labeling of the graph's vertices with colors such that no two verti ...
- pat甲级 1154 Vertex Coloring (25 分)
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...
- PAT 甲级 1154 Vertex Coloring
https://pintia.cn/problem-sets/994805342720868352/problems/1071785301894295552 A proper vertex color ...
- PAT Advanced 1020 Tree Traversals (25 分)
1020 Tree Traversals (25 分) Suppose that all the keys in a binary tree are distinct positive integ ...
- PAT Advanced 1134 Vertex Cover (25) [hash散列]
题目 A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at ...
- PAT Advanced 1071 Speech Patterns (25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- PAT Advanced 1048 Find Coins (25 分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...
- PAT Advanced 1085 Perfect Sequence (25) [⼆分,two pointers]
题目 Given a sequence of positive integers and another positive integer p. The sequence is said to be ...
- PTA 1154 Vertex Coloring
题目链接:1154 Vertex Coloring A proper vertex coloring is a labeling of the graph's vertices with colors ...
随机推荐
- Milo-OPC UA处理Subscription和Triggering
Subscription有两种模式,一种是Reporting,另一种是Sampling. 如果定义为Sampling,则这个Subscription是一个Triggered Item,即被激发的订阅, ...
- Shader 中的颜色计算
下面介绍 Shader 中 gl_FragColor 的计算与转换: 一.颜色计算 1. 加 这里要讲讲三原色和三基色:三原色一般指的是红.绿.蓝三种,简称 RGB,这是加色系.就是光源只含有特定的波 ...
- kali PIN码破解
airmon-ng start wlan0 //开启网卡airodump-ng wlan0mon //监听模式,查找开启wps的apreaver -i wlan0mon -b [ap’s m ...
- [转帖]订购微软Windows 7延长支持服务的报价曝光 第三年要价两百美金
订购微软Windows 7延长支持服务的报价曝光 第三年要价两百美金 cnbeta 年2月份的新闻 https://www.cnbeta.com/articles/tech/815885.htm 微软 ...
- python 基础例子 双色球 查询天气 查询电话
# 随机生成双色球import random# 随机数 1-16之间# r = random.randint(1,16)# print(r)phone_numbers_str = "匪警[1 ...
- spark调优篇-oom 优化(汇总)
spark 之所以需要调优,一是代码执行效率低,二是经常 OOM 内存溢出 内存溢出无非两点: 1. Driver 内存不够 2. Executor 内存不够 Driver 内存不够无非两点: 1. ...
- skywalking-agent 与docker组合使用
docker部署 公司有使用docker部署的微服务 可以直接使用 仓库/java:8-jdk-alpine-asla-shanghai-1-skyagent-2作为基础镜像 这个镜像包是java8 ...
- HTTP协议探究(二):代理、网关和隧道
一 复习与目标 1 复习 缓存目的:减轻服务器压力,不重复请求相同的内容 缓存位置:浏览器或中间代理 相关状态码:200或403 相关首部: etag和since-none-match.last-mo ...
- MySQL修改和查看表类型
//修改表类型alter table verify_code engine = MEMORY;//查看表类型show create table verify_code;
- 查找最大和次大元素(JAVA版)(分治法)
问题描述:对于给定的含有n个元素的无序序列,求这个序列中最大和次大的两个不同元素. 问题求解分析(分治法):先给出无序序列数组a[low...high].第一种情况为当数组中只有一个元素时,此时只存在 ...