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 ...
随机推荐
- Bootstrap, 模态框实现值传递,自动勾选
目录 Bootstrap,模态框自动勾选,值传递 1.父页面 2. 子页面(modal) 模态框 Bootstrap,模态框自动勾选,值传递 场景: 有一个这样的需求, 在父页面有一个table, ...
- Lua中用table统一管理需要获取的unity物体
unity上的组件,可以用table统一管理 然后在初始化时候统一给table赋值,这样需要用到时候直接调用table中对应的key便可拿到对应的物体,省下了在脚本开头一堆声明的脚本,这样就不用声明这 ...
- linux基础之文件类型与权限
在终端以root身份登入linux之后,下达 ls -al 会获得如下结果
- Linux进程批量管理工具
在使用docker容器时,可以有单机的docker-compose批量编排工具,甚至还有集群的k8s之类编排工具,那么在Linux系统中同样也有相关的批量管理进程的工具,其中使用最多的应该就是supe ...
- 静态路由、RIP、OSPF、BGP
主要内容包含以下四点:(1)静态路由 (2)动态路由 (3)生成树 (4)VLAN 1. 什么是静态路由? 答:静态路由是管理人员手动配置和管理的路由 2. 静态路由由那些优点? 答:配置简单 ...
- jdk1.8 -- Collectors 的使用
package com.collector; import java.util.ArrayList; import java.util.Arrays; import java.util.Collect ...
- [转帖]windows CIFS sabma协议识
windows CIFS sabma协议识别 https://www.cnblogs.com/tcicy/p/9992871.html 公司的一个共享服务器就是 win2003的 mount 的时候 ...
- MySQL主从同步报错1507
mysql 从库上手动删除partiton后,主库未做修改.后期主库上删除partiton后,出现问题. 故障现场 Last_Errno: 1507 Last_Error: Error 'Error ...
- Java操作Excle(基于Poi)
有一次有个同事问我会不会有java操作Excle,回答当然是不会了!感觉被嘲讽了,于是开始寻找度娘,找到个小例子,结果越写越有意思,最后就成就了这个工具类. import java.io.Buffer ...
- 关于SpringMVC中的转发与重定向的说明
写的非常详细,参看该地址:https://www.zifangsky.cn/661.html 总结: 1.请求转发:url地址不变,可带参数,如?username=forward 2.请求重定向:ur ...