Source:

PAT A 1154 Vertex Coloring (25 分)

Description:

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

Keys:

Attenrion:

  • 矩阵存储图,规模小于10^3
  • 对于多组测试用例的输入,要注意统计值和哈希函数的初始化(出题老师太坏了,测试用例即使不初始化也是对的-,-)

Code:

 /*
Data: 2019-08-02 21:08:29
Problem: PAT_A1154#Vertex Coloring
AC: 17:39 题目大意:
判断图中相连的顶点是否共色
*/
#include<cstdio>
#include<set>
using namespace std;
const int M=1e4+;
struct node
{
int u,v;
}grap[M];
int color[M]; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,m,k;
scanf("%d%d", &m,&n);
for(int i=; i<n; i++)
scanf("%d%d", &grap[i].u,&grap[i].v);
scanf("%d", &k);
while(k--)
{
set<int> mp;
for(int i=; i<m; i++)
{
scanf("%d", &color[i]);
mp.insert(color[i]);
}
for(int i=; i<n; i++)
{
if(color[grap[i].u] == color[grap[i].v])
{
mp.clear();
break;
}
}
if(mp.size())
printf("%d-coloring\n", mp.size());
else
printf("No\n");
} return ;
}

PAT_A1154#Vertex Coloring的更多相关文章

  1. PAT 甲级 1154 Vertex Coloring

    https://pintia.cn/problem-sets/994805342720868352/problems/1071785301894295552 A proper vertex color ...

  2. pat甲级 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 分)

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

  4. PTA 1154 Vertex Coloring

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

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

  6. PAT-1154(Vertex Coloring )+map使用+vector建图+set的使用

    Vertex Coloring PAT-1154 #include<iostream> #include<cstring> #include<string> #in ...

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

  8. vtkMapper

    本文只是整理了该网页的内容:http://www.cnblogs.com/lizhengjin/archive/2009/08/16/1547340.html vtkMapper是一个抽象类,指定了几 ...

  9. Java基础常见英语词汇

    Java基础常见英语词汇(共70个) ['ɔbdʒekt] ['ɔ:rientid]导向的                             ['prəʊɡræmɪŋ]编程 OO: object ...

随机推荐

  1. [bzoj4025]二分图_LCT

    二分图 bzoj-4025 题目大意:给定一个n个节点的图,m条边,每条边有一个产生时间和一个删除时间,询问所有时间点是否是连通图. 注释:$1\le n\le 10^5$,$1\le m\le 2\ ...

  2. Spring for Apache Kafka @KafkaListener使用及注意事项

    官方文档:   https://docs.spring.io/spring-kafka/reference/html/ @KafkaListener The @KafkaListener annota ...

  3. 被AppStore拒绝理由(一)

    July 8, 2015 at 7:06 AM 发件人 Apple 17.1 - Apps cannot transmit data about a user without obtaining th ...

  4. java调用c++ dll出现中文乱码

    近期的开发用到了使用java调用本机动态连接库的功能,将文件路径通过java调用C++代码对文件进行操作. 在调用中假设路径中包括有中文字符就会出现故障.程序执行就会中止. 以下用一个小样例,来说明记 ...

  5. 关于oracle 11g导出数据时 报 ORA 1455错误的处理

    因为导出的该用户的表可能存在空数据表,那么可能就会出现此其异常. 首先:  查看:     SQL>show parameter deferred_segment_creation;  假设为T ...

  6. iOS-UIWebview比例缩放

    你在使用UIWebview显示网页时.可能会注意到.UIWebView所支持的缩放倍率是非常有限的.而在Safari自己所支持的缩放系数比UIWebview要大得多. 本文解释了怎样加大UIWebVi ...

  7. axis2的wsdl无法使用eclipse axis1插件来生成client--解决方法

    使用jetty+axis2实现webservice服务端,且无需使用axis2命令生成服务端代码.仅仅要services.xml配置实现类. project为gradleproject配置文件在src ...

  8. 在ubuntu中安装photoshop cs6

    对于很多专业的PS高手来说,真心难以找到顺手的且可以完美替代PS的软件,所以我们这里的解决办法就是用wine来安装. 虽然网上有很多的wine安装ps的方法,但是在使用过程往住会发生莫名其妙的崩溃,体 ...

  9. Java-java-com-util-common-service:CrudService.java

    ylbtech-Java-java-com-util-common-service:CrudService.java 1.返回顶部 1. package com.shineyoo.manager.ut ...

  10. [Apple开发者帐户帮助]五、管理标识符(4)注册一个应用程序组

    您需要注册一个或多个组才能启用应用组. 所需角色:帐户持有人或管理员. 在“ 证书”,“标识符和配置文件”中,从左侧的弹出菜单中选择操作系统. 在“标识符”下,选择“应用程序组”,然后单击右上角的“添 ...