PAT 甲级 1154 Vertex Coloring
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的更多相关文章
- 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 Advanced 1154 Vertex Coloring (25 分)
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...
- 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 ...
- PTA 1154 Vertex Coloring
题目链接:1154 Vertex Coloring A proper vertex coloring is a labeling of the graph's vertices with colors ...
- PAT 甲级 1134 Vertex Cover
https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...
- PAT甲级——1134 Vertex Cover (25 分)
1134 Vertex Cover (考察散列查找,比较水~) 我先在CSDN上发布的该文章,排版稍好https://blog.csdn.net/weixin_44385565/article/det ...
- 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 ...
- 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 ...
- PAT_A1154#Vertex Coloring
Source: PAT A 1154 Vertex Coloring (25 分) Description: A proper vertex coloring is a labeling of the ...
随机推荐
- python基础学习1-迭代器
#!/usr/bin/env python # -*- coding:utf-8 -*- #自定义迭代器 需要 重写 __iter__()和__next__() 两个魔法方法 class Fibs: ...
- 关于iptables命令
iptables 指令语法:iptables [-t table] command [match] [-j target/jump]-t 参数用来指定规则表,内建的规则表有三个,分别是:nat.man ...
- angularjs 常用方法
一 angular的copy和extend 1.angular.extend() angular.extend():依次将第二个参数及后续的参数的第一层属性(不管是简单的属性还是对象)拷贝,赋给第一个 ...
- 利用BlockingCollection实现生产者和消费者队列,实现写文本
最近开发几个小项目,需要把结果写到txt文件里面,并且按照时间进行分文件,由于对于效率要求较高,所以采用 生产者和消费者 模型来进行写出文本,线程中只需要添加队列就立即返回,而不需要等待写文件的时间 ...
- C++构造函数和析构函数什么情况下会用
析构函数: 1. 对象生命周期结束,被销毁时: 2. delete 指向对象的指针时: 3. delete 指向基类对象的指针时,其析构函数是虚函数: 4. 在嵌套关系中,对象A是对象B的成员,当对象 ...
- C/S结构与B/S结构
按照是否需要访问网络,程序可分为网络程序与非网络程序.其中网络程序又可分为B/S结构与C/S结构. C/S结构是指客户端(Client)/服务器(Server)模式,这种模式的客户端中 需要安装一个R ...
- 关于如何准备CKA考试
最近(2019年4月)通过了CKA考试,在此分享一下考试心得. CKA全称Certified Kubernetes Administrator,是一门在线考试,全程需要向考官分享摄像头和屏幕,考试费用 ...
- tensorflow-gpu与CUDA、CUDNN的版本问题
折腾了将近两天的时间,终于搞好了,感觉把所有的坑都踩过了一遍.....泪牛满面 1.先安装CUDA,并安装,尽量不要下载最新版本的,坑,本机可以下载最新本10.0版本,但与CUDNN和tensorfl ...
- eclipse xml文件中按alt+/没有提示信息
转载地址:http://blog.sina.com.cn/s/blog_972ddc1b01012mmh.html 今天要写这篇博文是因为遇到这样的不是技术的问题,但找到问题根源再解决这个问题又花费很 ...
- mkdir命令详情
基础命令学习目录首页 原文链接:https://blog.csdn.net/zwlove5280/article/details/74618041 mkdir 是创建目录的命令. 创建一级目录 mkd ...