当前位置:网站首页>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
边栏推荐
- 美智光电IPO被终止:年营收9.26亿 何享健为实控人
- 我,28岁,测试员,10月无情被辞:想给还在学测试 的人提个醒......
- [summer daily question] Luogu p6336 [coci2007-2008 2] bijele
- PAT甲级 1150 旅行商问题
- log4j Layout简介说明
- 7-2 计算正五边形的面积和周长 (25分)
- Scala 高阶(九):Scala中的模式匹配
- 2022年深圳杯A题破除“尖叫效应”与“回声室效应”走出“信息茧房”
- 【暑期每日一题】洛谷 P1601 A+B Problem(高精)
- 【暑期每日一题】洛谷 P6408 [COCI2008-2009#3] PET
猜你喜欢

Prometheus and grafana

新生代公链再攻「不可能三角」

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

Segger's hardware anomaly analysis

女研究生做“思维导图”与男友吵架!网友:吵架届的“内卷之王”....
![[summer daily question] Luogu p7760 [coci2016-2017 5] tuna](/img/9a/f857538c574fb54bc1accb737d7aec.png)
[summer daily question] Luogu p7760 [coci2016-2017 5] tuna

I, 28, a tester, was ruthlessly dismissed in October: I want to remind people who are still learning to test

Getting started with JDBC

Some learning and understanding of vintage analysis

使用自定义注解校验list的大小
随机推荐
关于大龄读博的几点回答?
JS break and continue and return keywords
Segger's hardware anomaly analysis
Docker最新超详细教程——Docker创建运行MySQL并挂载
程序的静态库与动态库的区别
Clock tree synthesis (I)
【暑期每日一题】洛谷 P4413 [COCI2006-2007#2] R2
性能更佳、使用更简单的懒加载IntersectionObserverEntry(观察者)
2022年深圳杯A题破除“尖叫效应”与“回声室效应”走出“信息茧房”
力扣(LeetCode)209. 长度最小的子数组(2022.07.28)
5-integrate swagger2
【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK
美智光电IPO被终止:年营收9.26亿 何享健为实控人
女研究生做“思维导图”与男友吵架!网友:吵架届的“内卷之王”....
0 8 动态规划(Dynamic Programming)
What is the function of fileappender in logback?
Gin service exit
0 9 布隆过滤器(Bloom Filter)
How to establish EDI connection with Scania in Scania?
Does Flink support sqlserver databases? Get the changes of SQLSERVER database