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. truffle init Error:连接不到github网址

    问题描述: 输入truffle init 输出 Error: Error making request to https://raw.githubusercontent.com/truffle-box ...

  2. c++学习笔记_3

    前言:本笔记所对应的课程为中国大学mooc中北京大学的程序设计与算法(三)C++面向对象程序设计,主要供自己复习使用,且本笔记建立在会使用c和java的基础上,只针对与c和java的不同来写 类和对象 ...

  3. 【VS开发】C/C++预编译命令

    C/C++中宏总结C程序的源代码中可包括各种编译指令,这些指令称为预处理命令或预处理器.虽然它们实际上不是C语言的一部分,但却扩展了C程 序设计的环境. 预处理指令的主要作用就是把通过预处理的内建功能 ...

  4. mysql 全表扫描场景

    全表扫描是数据库搜寻表的每一条记录的过程,直到所有符合给定条件的记录返回为止.通常在数据库中,对无索引的表进行查询一般称为全表扫描:然而有时候我们即便添加了索引,但当我们的SQL语句写的不合理的时候也 ...

  5. when i import skimage,it occurred --"cannot import name '_validate_lengths'"

    how to sovle this prolem? 1)with the administrator user to run cmd 2)imput and run : pip install --u ...

  6. Nginx 小入门记录 之 Nginx 配置文件解读(二)

    上一小节主要是记录一些环境准备和Nginx的安装,接下来对Nginx基本配置进行记录. 查看配置文件安装记录 可以通过以下Linux命令进行查看: rpm -ql nginx rpm 是liunx的包 ...

  7. Linux下文件搜索、查找、查看命令

    Linux下文件搜索.查找.查看命令 1.最强大的搜索命令:find 查找各种文件的命令 2.在文件资料中查找文件:locate 3.搜索命令所在的目录及别名信息:which 4.搜索命令所在的目录及 ...

  8. 【AtCoder】ARC064

    ARC064 C - Boxes and Candies 先把每个盒子都消到x 然后从前往后推,要求第二个的上界是x-前一个 因为我们要求靠后的那个尽量小,会对后面的修改影响尽量小 #include ...

  9. 剑指offer14:输入一个链表,输出该链表中倒数第k个结点。

    1. 题目描述 输入一个链表,输出该链表中倒数第k个结点. 2. 思路和方法 可以用两个指针,一个指针遍历到第k个结点的时候,第二个指针再走到第一个节点,然后两个指针的距离始终保持k-1.这样,当第一 ...

  10. windows下安装mongoDB(zip版)

    windows下安装mongoDB(zip版) 下面说明如何在win10下用zip包安装好mongoDB数据库 首先要先从网上下载mongoDB的zip包 http://dl.mongodb.org/ ...