当前位置:网站首页>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
边栏推荐
猜你喜欢
![[summer daily question] Luogu p7760 [coci2016-2017 5] tuna](/img/9a/f857538c574fb54bc1accb737d7aec.png)
[summer daily question] Luogu p7760 [coci2016-2017 5] tuna

第7节-程序的编译(预处理操作)+链接

电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?

QT连接两个qslite数据库报错QSqlQuery::exec: database not open

分析25个主要DeFi协议的路线图 预见DeFi未来的七大趋势

梳理市面上的2大NFT定价范式和4种解决方案

MySQL uses the client and select methods to view the summary of blob type fields

Practice of online problem feedback module (XVII): realize the online download function of excel template

2-unified return class dto object
Scala 高阶(十):Scala中的异常处理
随机推荐
[summer daily question] Luogu p4413 [coci2006-2007 2] R2
Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays
我想问一下,我flink作业是以upsert-kafka的方式写入数据的,但是我在mysql里面去更
1-后台项目搭建
Gin routing, parameters, output
QT basic day 2 (2) QT basic components: button class, layout class, output class, input class, container and other individual examples
Clock tree synthesis (I)
蓝桥杯A组选数异或
[summer daily question] Luogu P6500 [coci2010-2011 3] zbroj
jdbc入门
分析25个主要DeFi协议的路线图 预见DeFi未来的七大趋势
UPC 小C的王者峡谷
Scala 高阶(九):Scala中的模式匹配
亚马逊云助手小程序来啦!
Zabbix 其他基础监控项
计算程序运行时间 demo
do end用法的妙处
How to use GS_ Expansion expansion node
[summer daily question] Luogu p1601 a+b problem (high precision)
Gin parameter validation