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 分)的更多相关文章

  1. 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 ...

  2. pat甲级 1154 Vertex Coloring (25 分)

    A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...

  3. PAT 甲级 1154 Vertex Coloring

    https://pintia.cn/problem-sets/994805342720868352/problems/1071785301894295552 A proper vertex color ...

  4. PAT Advanced 1020 Tree Traversals (25 分)

    1020 Tree Traversals (25 分)   Suppose that all the keys in a binary tree are distinct positive integ ...

  5. 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 ...

  6. PAT Advanced 1071 Speech Patterns (25 分)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  7. PAT Advanced 1048 Find Coins (25 分)

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

  8. 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 ...

  9. PTA 1154 Vertex Coloring

    题目链接:1154 Vertex Coloring A proper vertex coloring is a labeling of the graph's vertices with colors ...

随机推荐

  1. Unity3d Terrain splat 9 is null 解决方法

    是因为地形的 材质刷和树木或者草的刷子丢失引起.重新赋值或者删除掉就可以了

  2. <marquee>滚动文字</marquee>

    <marquee>滚动文字</marquee> 水平滚动: <marquee direction=">水平滚动字幕内容</marquee> 垂 ...

  3. 【AMAD】django-debug-toolbar -- 一个可配置的panel,展示当前request/response的debug信息

    简介 个人评分 简介 django-debug-toolbar1是一个django开发工具,可以在你开发django页面的时候展示一些当前请求的debug信息:  个人评分 类型 评分 实用性 ⭐️ ...

  4. java内存回收需要了解的知识

    你是否有过这样的经历,跑得好好的Java进程,突然就瘫痪了?多数Java进程瘫痪的原因可以从java虚拟机层面找到原因. 1.什么情况下会执行gc 为了了解我们的系统为什么会不停fgc,我们需要先了解 ...

  5. 【转】MySql 三大知识点——索引、锁、事务

    索引 索引,类似书籍的目录,可以根据目录的某个页码立即找到对应的内容. 索引的优点:1. 天生排序.2. 快速查找. 索引的缺点:1. 占用空间.2. 降低更新表的速度. 注意点:小表使用全表扫描更快 ...

  6. loback的介绍与配置-(通俗易通)

    一.logback的配置介绍 Logback的配置分为三个内容:Logger.appender及layout Logger:作为日志的记录器,主要用于存放日志对象,也可以定义日志类型.级别. appe ...

  7. [转帖]Oracle 起诉 Google 事件

    Oracle 起诉 Google 事件 https://www.cnblogs.com/panchanggui/p/9449842.html Oracle 是世界第二大软件公司 世界第一大DBMS公司 ...

  8. TIME_WAIT和CLOSE_WAIT的区别

    系统上线之后,通过如下语句查看服务器时,发现有不少TIME_WAIT和CLOSE_WAIT. netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) ...

  9. Python解Leetcode: 1. Two Sum

    题目描述:求出数组中等于目标值的两个数的索引,假定肯定存在两个数并且同一个索引上的数不能用两次. 思路: 用空间换时间,使用一个字典存储已经遍历的数字的索引,如果新遍历的数字和target的差值在字典 ...

  10. ingress之tls和path使用

    ingress tls 上节课给大家展示了 traefik 的安装使用以及简单的 ingress 的配置方法,这节课我们来学习一下 ingress tls 以及 path 路径在 ingress 对象 ...