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. Scala中=>的用法

    1. 表示函数的类型(Function Type) 例如: def double(x: Int): Int = x*2 函数double的类型就是 (x: Int) => Int 或者 Int ...

  2. mfc 类

    知识点 类的概念 类的相关术语 定义类 使用类 一.类的概念 简单的说类就是数据与函数综合体,它是用户自定义类型. 二.类的相关术语 类的实例称为对象. 类在定义中隐式地包含数据和操作函数,这种思想称 ...

  3. 很详细的SpringBoot整合UEditor教程

    很详细的SpringBoot整合UEditor教程 2017年04月10日 20:27:21 小宝2333 阅读数:21529    版权声明:本文为博主原创文章,未经博主允许不得转载. https: ...

  4. asp.net core 发布到docker 极简步骤

    1.使用dotnet命令发布项目 2.把发布成功的文件通过scp等工具发布到linux服务器上,在当前目录下新建一个dockerfile 3.使用asp.net core镜像为底包构建一个新的镜像 4 ...

  5. Python练习——矩形、直角三角形、乘法表

    一.矩形 #******输入行和列,打印相应的矩形******# width = input("宽:") longth = input("长:") if (wi ...

  6. Qt-网易云音乐界面实现-1 窗口隐藏拖拽移动,自定义标题栏

    最近也换了公司,也换了新的工作,工资也象征性的涨了一点点,但是最近心里还是慌慌,不知道为什么,没有那种踏实感,感觉自己随时可以被抛弃的感觉.感觉自己在荒废时间,也感觉自己在浪费生命. 为了让自己在被抛 ...

  7. STM平台增加性能测试/稳定性测试部分【二】

    [一]方案 基本上测试针对产品的各项方案大体是如下的: 如上所示,针对产品的性能测试主要步骤如下: 1.造数据,在产品业务流上,产生所需的数据,数据量以(稳定性或者压测指标确定) 2.根据步骤1,设定 ...

  8. Android Bitmap

    一 图片表示原理 图片是由每个像素点来组成 像素点就是小方块 图片的大小等于 宽*高*每个像素点的大小 二 加载图片OOM异常 解决办法 其中big.jpg是一张21.2MB的高清图 public c ...

  9. WPF中的颜色转换

    HEX16色转Bursh: Brush brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFF ...

  10. alibaba/fescar 阿里巴巴 开源 分布式事务中间件

    Fescar 是 阿里巴巴 开源的 分布式事务中间件,以 高效 并且对业务 0 侵入 的方式,解决 微服务 场景下面临的分布式事务问题. 示例:https://github.com/windwant/ ...