当前位置:网站首页>PAT甲级 1154 顶点着色
PAT甲级 1154 顶点着色
2022-07-29 07:01:00 【键盘奏鸣曲】
一个合适的顶点着色是指用各种颜色标记图中各个顶点,使得每条边的两个端点的颜色都不相同。
如果一种合适的顶点着色方案使用了一共 k 种不同的颜色,则称其为合适的 k 着色(k-coloring)。
现在,你需要判断给定的着色方案是否是合适的 k 着色方案。
输入格式
第一行包含两个整数 N 和 M,分别表示点和边的数量。接下来 M 行,每行包含两个整数 a,b,表示点 a 和点 b 之间存在一条边。
所有点的编号从 0 到 N−1。
再一行包含一个整数 K,表示你需要判断的着色方案。
接下来 K 行,每行包含 N 个颜色,其中第 i 个颜色表示第 i 个点的颜色。
颜色用非负整数表示,不超过 int 范围。
输出格式
对于每种着色方案,如果是一种合适的 k 着色方案,则输出一行 k-coloring。如果不是合适的着色方案,则输出一行 No。
数据范围
1≤N,M≤104,
1≤K≤100
输入样例:
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
输出样例:
4-coloring
No
6-coloring
No
我的解法:
#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;
}收获:
在数组中,用unordered_set<int>统计共有几种数字出现
插入方式 S.insert()
遍历方式 for(auto c : S)
与set区别:
set自动排序,unordered_set不自动排序
边栏推荐
- 2022-07-28: what is the output of the following go language code? A:AA; B:AB; C:BA; D:BB。 package main import ( “fmt“ ) func main() { f
- 5-integrate swagger2
- Paper reading (62):pointer networks
- SpingBoot整合Quartz框架实现动态定时任务(支持实时增删改查任务)
- 2-unified return class dto object
- Zabbix 其他基础监控项
- Fillder use
- 如何与斯堪尼亚SCANIA建立EDI连接?
- ETL为什么经常变成ELT甚至LET?
- tp6 使用 ProtoBuf
猜你喜欢

H3C_利用设置缺省静态路由优先级实现出口双线路的主备功能

ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法

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

WPF interface layout must know basis

leetcode力扣经典问题——4.寻找两个正序数组的中位数

用户列表 圆形头像并跟随小板块

Why does ETL often become ELT or even let?

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

Kubernetes (五) ---------部署 Kubernetes Dashboard

使用VsCode配置MySQL实现连接、查询、等功能
随机推荐
[100 cases of unity practice] the single choice multiple choice judgment questions of unity universal question answering system are all common
7-2 计算正五边形的面积和周长 (25分)
Win11vmware turns on the virtual machine and restarts on the blue screen and the solution that cannot be started
Win11 system error: code execution cannot continue because ierutil.dll cannot be found. Reinstalling the program may fix this problem
Gin Middleware
Synchronous / asynchronous, blocking / non blocking and IO
ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法
Gin service exit
Some learning and understanding of vintage analysis
Kubernetes (五) ---------部署 Kubernetes Dashboard
leetcode力扣经典问题——4.寻找两个正序数组的中位数
Fillder use
How to use GS_ Expansion expansion node
mysql 单表最多能存多少数据?
js中break与continue和return关键字
Section 7 - compilation of programs (preprocessing operations) + links
路由中的生命周期钩子 - activated与deactivated
在线问题反馈模块实战(十七):实现excel模板在线下载功能
Vmware16 create virtual machine: cannot create a new virtual machine, do not have permission to perform this operation
力扣(LeetCode)209. 长度最小的子数组(2022.07.28)