当前位置:网站首页>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
边栏推荐
- 我,28岁,测试员,10月无情被辞:想给还在学测试 的人提个醒......
- Synchronous / asynchronous, blocking / non blocking and IO
- Introduction to log4j layout
- Android面试题 | 怎么写一个又好又快的日志库?
- Leetcode 209. subarray with the smallest length (2022.07.28)
- [MySQL] - [subquery]
- 亚马逊云助手小程序来啦!
- 性能更佳、使用更简单的懒加载IntersectionObserverEntry(观察者)
- Gin routing, parameters, output
- 树莓派的启动流程
猜你喜欢
![[summer daily question] Luogu p6461 [coci2006-2007 5] trik](/img/bf/c0e03f1bf477730f0b3661b3256d1d.png)
[summer daily question] Luogu p6461 [coci2006-2007 5] trik

Getting started with JDBC

halcon的安装以及在vs2017中测试,vs2017中dll的配置
![【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK](/img/bf/c0e03f1bf477730f0b3661b3256d1d.png)
【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK

零数科技深度参与信通院隐私计算金融场景标准制定

Can the subset of the array accumulate K

thinkphp6 实现数据库备份

js第四天流程控制(if语句和switch语句)

1 - background project construction

STM32 operation w25q256 w25q16 SPI flash
随机推荐
Docker's latest super detailed tutorial - docker creates, runs, and mounts MySQL
gcc/g++的使用
QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
3-全局异常处理
程序的静态库与动态库的区别
3-global exception handling
2-统一返回类DTO对象
1 - background project construction
Log4qt memory leak, use of heob memory detection tool
zip gzip tar压缩进阶版
Levelfilter introduction
Gin template
2-unified return class dto object
Gin Middleware
Explanation of suffix automata (SAM) + Luogu p3804 [template] suffix automata (SAM)
logback日志级别简介说明
7-2 calculate the area and perimeter of a regular pentagon (25 points)
LevelFilter简介说明
WPF nested layout case
【暑期每日一题】洛谷 P7760 [COCI2016-2017#5] Tuna