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. Jetson TX2 不同的工作模式

    Jetson TX2 有五种工作模式,下面介绍这几种工作模式下电压.频率以及如何启动. 原理图 几种不同的工作模式 mode mode name Denver Frequency ARM Freque ...

  2. thinkphp5相关

    THINKPHP5代码风格规范(基于PSR): https://www.jianshu.com/p/e53d26407e68

  3. nssm设置solr开机启动服务

    首先,下载nssm http://www.nssm.cc/download 命令 nssm install solr 然后到服务里启动solr,并设置为自动 Ctrl+Shift+Esc(说明:Esc ...

  4. Mybatis之自动生成

    使用Mybatis来自动生成我们的dao接口,mapper文件和实体类. 1.pom.xml依赖: <dependencies> <dependency> <groupI ...

  5. hdoj1561 The more, The Better (树形dp,分组背包)

    题目链接:https://vjudge.net/problem/HDU-1561 题意:给一个森林,每个结点有个权值,求选m个结点的最大权值和,并且选子结点前必须先选父结点. 思路: 把每颗树的树根连 ...

  6. Android5以后WebView闪退问题

    Android4.4开发项目中的webview在Android各个版本运行的飞起,可是项目升级,最低版本适配5.0之后,webview各种闪退问题 真让人头大!!!!!!!!!!!!!!! 啊啊啊啊啊 ...

  7. Java虚拟机内存管理小结

  8. pat L2_004

    一棵二叉搜索树可被递归地定义为具有下列性质的二叉树:对于任一结点, 其左子树中所有结点的键值小于该结点的键值: 其右子树中所有结点的键值大于等于该结点的键值: 其左右子树都是二叉搜索树. 所谓二叉搜索 ...

  9. PowerDesigner最基础的使用方法

    1:入门级使用PowerDesigner软件创建数据库(直接上图怎么创建,其他的概念知识可自行学习) 我的PowerDesigner版本是16.5的,如若版本不一样,请自行参考学习即可.(打开软件即是 ...

  10. 多线程之thread和runnable

    Runnanle方式可以避免Thread由于单继承特性带来的缺陷. Runnable代码可以被多个线程(thread实例)共享,适用于多个线程处理同一资源的情况. 线程的生命周期:创建,就绪,阻塞,运 ...