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. Android开发——代码中实现WAP方式联网

    ,移动和联通的WAP代理服务器都是10.0.0.172,电信的WAP代理服务器是10.0.0.200. 在Android系统中,对于获取手机的APN设置,需要通过ContentProvider来进行数 ...

  2. 简单的贝叶斯分类器的python实现

    # -*- coding: utf-8 -*- ''' >>> c = Classy() >>> c.train(['cpu', 'RAM', 'ALU', 'io ...

  3. 4-[HTML]-body常用标签1

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. C#中如果类的扩展方法和类本身的方法签名相同,那么会优先调用类本身的方法

    新建一个.NET Core项目,假如我们有如下代码: using System; namespace MethodOverload { static class DemoExtension { pub ...

  5. Memached、Redis、Mongodb的区别

    性能 ​ • 性能都很高,redis和memached差不多 > Mongodb 操作 ​ • Memached:数据结构单一,只有key/value数据结构 ​ • Redis有五种数据类型 ...

  6. lua字符串类型

    Lua中字符串结构体的定义是: typedef union TString { L_Umaxalign dummy; /* ensures maximum alignment for strings ...

  7. 关于kafka的一些问题理解

  8. Python实现学生系统

    # 4. 修改之前的学生信息管理程序,实现添加菜单和选择菜单操作功能: # 菜单: # +-----------------------------+ # | 1) 添加学生信息 | # | 2) 查 ...

  9. SparkRDD编程实战

    通过spark实现点击流日志分析案例 1. 访问的pv package cn.itcast import org.apache.spark.rdd.RDD import org.apache.spar ...

  10. python-模拟掷骰子,两个筛子数据可视化

    """ 作者:zxj 功能:模拟掷骰子,两个筛子数据可视化 版本:3.0 日期:19/3/24 """ import random impo ...