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 ...
随机推荐
- TCP/IP协议、HTTP协议
一.序: TCP/IP协议是程序开发的基础知识,我们都知道它可以实现不同计算机之间的通信,它是什么意思?怎么实现通信的? 二.TCP/IP协议: (1)协议:约定 (2)tcp/ip:tcp是传输控制 ...
- 如何查看win2003是32位还是64位
如何查看自己的电脑是32位还是64位 方法如下: 点击开始——运行——输入wmic cpu get addresswidth
- c++ 文件共享打开
_fsopen参数说明 #include<share.h> _fsopen 共享模式访问文件 //安全性比fopen高 _fsopen 以共享的方式打开文件或者流 FILE * ...
- 【转载】D3DXMatrixLookAtLH视图变换函数详解
原文:D3DXMatrixLookAtLH视图变换函数详解 /*D3DXMatrixLookAtLH函数返回的是世界->视图变换矩阵. 视图坐标系和局部坐标系是一样的,都是世界坐标系转换为指定的 ...
- 5469: [FJOI2018]领导集团问题
5469: [FJOI2018]领导集团问题 链接 题意: 要求在一棵树内选一个子集,满足子集内的任意两个点u,v,如果u是v的祖先,那么u的权值小于等于v. 分析: dp[u][i]表示在u的子树内 ...
- zabbix3调用接口发送短信告警
一.需求 之前使用的邮件告警,由于经常会忽略邮件,所以有时候告警查看的并不及时,所以增加短信告警的,以便及时处理. 二.zabbix-server端的配置 # 需要在zabbix-server端打开A ...
- 硬盘空间术语:unallocated, unused and reserved
通过standard reports查看Disk Usage,选中Database,右击,选择Reports->Standard Reports->Disk Space Usage,截图如 ...
- (转)js数组与字符串的相互转换方法
一.数组转字符串 需要将数组元素用某个字符连接成字符串,示例代码如下: var a, b; a = new Array(0,1,2,3,4); b = a.join("-"); 二 ...
- SQL Server存储过程用法介绍
存储过程其实就是已预编译为可执行过程的一个或多个SQL语句. 通过调用和传递参数即可完成该存储过程的功能. 前面有介绍过存储过程的一些语法,但是没有详细示例,今天我们来一起研究一下存储过程. 提高性能 ...
- JavaScript学习笔记(六)—— 异步编码
第七章 异步编码 1 事件处理程序 处理程序:即网页加载完毕后将执行的代码,称回调函数或监听器: 包含:处理函数+window.onload=函数名; <script language=&qu ...