当前位置:网站首页>Pat class a 1154 vertex shading
Pat class a 1154 vertex shading
2022-07-29 07:31:00 【Clavier sonata 】
A suitable vertex coloring refers to marking each vertex in the graph with various colors , Make the color of the two ends of each edge different .
If a suitable vertex shading scheme uses a total of k Plant different colors , Call it appropriate k To color (k-coloring).
Now? , You need to decide whether the given coloring scheme is appropriate k Coloring scheme .
Input format
The first line contains two integers N and M, Represent the number of points and edges respectively .Next M That's ok , Each line contains two integers a,b, Indication point a Sum point b There is an edge between .
Number of all points from 0 To N−1.
The next line contains an integer K, Indicates the coloring scheme you need to judge .
Next K That's ok , Each row contains N One color , Among them the first i The first color represents the second color i The color of a dot .
Colors are represented by non negative integers , No more than int Range .
Output format
For each coloring scheme , If it is a suitable k Coloring scheme , Then output a line k-coloring.If it is not a suitable coloring scheme , Then output a line No.
Data range
1≤N,M≤104,
1≤K≤100
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
My solution :
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n, m, k;
struct {
int a, b;
}Edge[N];
int color[N];
int main(){
cin >> n >> m;
for(int i = 0; i < m; i ++ ){
cin >> Edge[i].a >> Edge[i].b;
}
cin >> k;
while(k --){
bool success = true;
for(int i = 0; i < n; i ++ ) cin >> color[i];
for(int i = 0; i < m; i ++ ){
if(color[Edge[i].a] == color[Edge[i].b]) success = false;
}
if(success){
unordered_set <int> S;
for(int i = 0; i < n; i ++ ) S.insert(color[i]);
printf("%d-coloring\n", S.size());
}
else puts("No");
}
return 0;
}Harvest :
In the array , use unordered_set<int> There are several figures in statistics
Insert the way S.insert()
Traverse the way for(auto c : S)
And set difference :
set Automatic sorting ,unordered_set Don't automatically sort
边栏推荐
- 分析25个主要DeFi协议的路线图 预见DeFi未来的七大趋势
- PAT甲级 1146 拓扑顺序
- logback中RollingFileAppender属性简介说明
- [summer daily question] Luogu p4414 [coci2006-2007 2] ABC
- Scala 高阶(九):Scala中的模式匹配
- 在线问题反馈模块实战(十七):实现excel模板在线下载功能
- log4qt内存泄露问题,heob内存检测工具的使用
- Practice of online problem feedback module (XVII): realize the online download function of excel template
- CMOS芯片制造全工艺流程
- BeanUtils.setProperty()
猜你喜欢

1-后台项目搭建
Scala higher order (IX): pattern matching in Scala

Spingboot integrates the quartz framework to realize dynamic scheduled tasks (support real-time addition, deletion, modification and query tasks)
Scala 高阶(十):Scala中的异常处理

How does MySQL convert rows to columns?

QT基础第二天(2)qt基础部件:按钮类,布局类,输出类,输入类,容器等个别举例

Can the subset of the array accumulate K

如何与斯堪尼亚SCANIA建立EDI连接?

Meeting notice of OA project (Query & whether to attend the meeting & feedback details)

Log4qt memory leak, use of heob memory detection tool
随机推荐
【暑期每日一题】洛谷 P6500 [COCI2010-2011#3] ZBROJ
计算程序运行时间 demo
logback日志级别简介说明
Levelfilter introduction
状态机dp(简单版)
CDC source can quit after reading MySQL snapshot split
Female graduate students do "mind mapping" and quarrel with their boyfriend! Netizen: the "king of infighting" in the quarrel
Reflect reflect
Scala 高阶(九):Scala中的模式匹配
Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays
Introduction to logback appender
UPC 小C的王者峡谷
Android面试题 | 怎么写一个又好又快的日志库?
[summer daily question] Luogu p1601 a+b problem (high precision)
5-整合swagger2
基于高阶无六环的LDPC最小和译码matlab仿真
Gin routing, parameters, output
【暑期每日一题】洛谷 P6408 [COCI2008-2009#3] PET
js第四天流程控制(if语句和switch语句)
[summer daily question] Luogu p6461 [coci2006-2007 5] trik