https://pintia.cn/problem-sets/994805342720868352/problems/1071785301894295552

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 <bits/stdc++.h>
using namespace std; const int maxn = 1e4 + 10;
int N ,M, K;
vector<int> v[maxn];
map<int, int> mp; int main() {
scanf("%d%d", &N, &M);
while(M --) {
int a, b;
scanf("%d%d", &a, &b);
v[a].push_back(b);
v[b].push_back(a);
} scanf("%d", &K);
while(K --) {
mp.clear();
set<int> s;
s.clear();
for(int i = 0; i < N; i ++) {
int x;
scanf("%d", &x);
s.insert(x);
mp[i] = x;
} bool flag = true;
for(int i = 0; i < N; i ++) {
for(int j = 0; j < v[i].size(); j ++) {
if(mp[i] == mp[v[i][j]]) {
flag = false;
break;
}
}
if(flag) continue;
else break;
} if(!flag) printf("No\n");
else printf("%d-coloring\n", (int)s.size());
}
return 0;
}  

  今天第一题打卡 简单图论

FHFHFH

PAT 甲级 1154 Vertex Coloring的更多相关文章

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

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

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

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

  4. PTA 1154 Vertex Coloring

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

  5. PAT 甲级 1134 Vertex Cover

    https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...

  6. PAT甲级——1134 Vertex Cover (25 分)

    1134 Vertex Cover (考察散列查找,比较水~) 我先在CSDN上发布的该文章,排版稍好https://blog.csdn.net/weixin_44385565/article/det ...

  7. PAT甲级——A1134 Vertex Cover【25】

    A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...

  8. 1154 Vertex Coloring

    题目前半略 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 ...

  9. PAT_A1154#Vertex Coloring

    Source: PAT A 1154 Vertex Coloring (25 分) Description: A proper vertex coloring is a labeling of the ...

随机推荐

  1. JavaEE笔记(二)

    查询load()和get()的区别 # 以下查询都是根据id查询 // Load和Get都会在第一次查询的是创建一个一级缓存查询语句 // 下一次查询的时候从缓存中查询是否有缓存的语句 // 如果有只 ...

  2. tomcat : 虚拟路径映射

    tomcat设置虚拟访问地址和真实路径的映射,方法有几种,这里介绍常用的两种方式: 一.修改server.xml文件: 步骤如下:  1.在tomcat根目录下打开conf文件夹,该文件夹下有个ser ...

  3. [JLOI2013]地形生成[组合计数]

    题意 \(n\) 元素各有一个高度 \(h\) 和关键数字 \(b\) .求有多少个下标序列和高度序列,满足对任意 \(i\),\(j< i\) 且 \(h_j < h_i\)的 \(j\ ...

  4. android targetSdkVersion>=26收不到广播的处理

    背景:GP新政策,要求Google Player上架应用的targetSdkVersion>=26. 一. 为啥GP要求targetSdkVersion>=26? 1 targetSdkV ...

  5. 用 Python 破解 WIFI 密码,走到哪里都能连 WIFI

    WIFI 破解,Python 程序员必学技能.WIFI 已经完全普及,现在 Python 程序员没网,走到哪里都不怕! 教你们一招,如何在图片中提取 Python 脚本代码.图片发送至手机 QQ 长按 ...

  6. div滤镜结合ajax,实现登录

    一:登陆页面 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...

  7. BootStap学习笔记(1)

    移动设备优先:  为了让开发的网站对移动设备友好,确保适当的绘制和触屏缩放,需要在网页的head之中添加viewport meat标签:如下: <metaname="viewport& ...

  8. JDK 和 JRE 有什么区别

    JDK是Java开发工具包(Java Development Kit),JRE是Java运行环境(Java Runtime Environment),JDK包含了JRE,搭建Java环境的时候,安装J ...

  9. sqli-labs学习笔记 DAY6

    DAY 6 sqli-labs lesson 30 与上一题一样,需要用到HPP 查看源代码,参数两边加上了双引号,直接使用lesson 26a与lesson 27a的脚本即可 sqli-labs l ...

  10. lsblk命令详解

    基础命令学习目录首页 lsblk 默认是树形方式显示: $lsblk NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTsda      8:0    0   2. ...