1154 Vertex Coloring (25 point(s))

【信息科学与工程学】【数据科学】数据科学领域——第三篇 数学08 几何学00总篇 编号英文名称中文名称简要说明/归属1Foundations of Geometry几何基础公理化方法, Hilbert《几何基础》2Euclidean Geometry (Synthetic)欧几里得几何(综合法)《几何原本》传统3Analytic Geometry解析几何坐标方法, Descartes, Fermat4Plane Geometry平面几何三角形、圆、共点共线等经典问题5Solid Geometry立体几何三维空间中的图形与度量6Non-Euclidean Geometry非欧几何平行公设不 阅读详情

1154 Vertex Coloring (25 point(s))

A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k-coloring.

Now you are supposed to tell if a given coloring is a proper k-coloring.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N and M (both no more than 10​4​​), being the total numbers of vertices and edges, respectively. Then M lines follow, each describes an edge by giving the indices (from 0 to N−1) of the two ends of the edge.

After the graph, a positive integer K (≤ 100) is given, which is the number of colorings you are supposed to check. Then K lines follow, each contains N colors which are represented by non-negative integers in the range of int. The i-th color is the color of the i-th vertex.

Output Specification:

For each coloring, print in a line k-coloring if it is a proper k-coloring for some positive k, or No if not.

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

简单图论。

判断给定的涂色方案是否满足任何一条边的两个结点不同。如果满足,需要得到有多少个颜色。

使用vector<pair<int,int> > v来存储边,使用数组coloring[]来存储涂色方案。然后遍历每条边进行判断。颜色采用set去重实现。

#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
const int MAX = 1e4+7;
int N,M,q,a,b;
int coloring[MAX];
vector<pair<int,int> >v;
int main(void){
	cin>>N>>M;
	while(M--){
		cin>>a>>b;
		v.push_back(pair<int,int>(a,b));
	}
	cin>>q;
	set<int> s;
	while(q--){
		s.clear();
		for(int i=0;i<N;i++){
			 cin>>coloring[i];
			 s.insert(coloring[i]);
		}
		bool isOk = true;
		for(int i=0;i<v.size();i++){
			if(coloring[v[i].first]==coloring[v[i].second]){
				isOk =false;break;
			}
		}
		if(isOk) cout<<s.size()<<"-coloring"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

 

【信息科学与工程学】【通信工程】第八十六篇 通信网络设备及通信网络组网的所有学科知识01 编号001类型网络虚拟化与覆盖技术网络领域数据中心网络子领域大二层网络 / 网络虚拟化核心数学方程式/算法模型核心算法:VXLAN封装与解封装。关键在于24位VNI(虚拟网络标识符)到物理网络的三层IP地址的映射。封装:收到原始以太帧后,为其添加 VXLAN 头部(含 VNI)、外层 UDP 头(目的端口 4789)、外层 IP 头(源 IP 为本地 VTEP IP,目的 IP 为对端 VTEP IP)以及外层 MAC 头。解封装:对端 收到报文后,剥离外层头部,根据内层帧的目的 MAC 和 VNI 进行二 阅读详情

相关推荐

【信息科学与工程学】【数据科学】数据科学领域-第三篇 数学基础04 集合论02

编号类型概念类别概念名称数学定义/描述数学表示性质特征重要特例相关理论问题的数学分析参数列表及参数数值范围关联知识1基础集合论本体集合若干确定的、互不相同的对象的总体A,B,…确定性、互异性、无序性∅,N,RZFC 公理系元素归属判定 x∈A势 ∥A∥∈{finite}∪[ℵ0​,+∞)朴素集合论→公理化2基础集合运算并/交/差/补按逻辑联结词定义的集合操作A∪B,A∩B,A∖B交换律、结合律、分配律、De MorganA∪∅=A布尔代数多集合推广 ⋃i∈I​Ai​I为指标集,可数/不可数测度论3基础构造幂

weixin_49199313的博客 371

PAT Advanced 1154 Vertex Coloring (25 )

PAT Advanced 1154 Vertex Coloring (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code 题目描述 A proper vertex coloring is a labeling of the graph’s vertices with colors ...

gq__97的博客 250

消费级显卡跑大模型:RTX 3060 12G 部署 70 亿参数 AI 编程助手的优化实战

本文详细介绍了如何在消费级显卡RTX 3060 12G上,通过量化、投机解码和分页KV-Cache等核心优化技术,成功部署并流畅运行70亿参数的CodeLlama-7B编程助手。文章提供了从环境配置、模型准备到参数调优的完整实战笔记,实测显存占用降至7.3GB,生成速度达21.7 token/秒,为开发者和技术爱好者提供了可行的本地AI部署方案。

weixin_29053067的博客 1262

【PAT】A1113 Integer Set Partition (25 point(s))

文章目录A1113 Integer Set Partition (25 point(s))Input Specification:Output Specification:Sample Input 1:Sample Output 1:Sample Input 2:Sample Output 2: A1113 Integer Set Partition (25 point(s)) Given a s...

Duke 296

AI大模型与碳足迹评估结合模式及示范案例

AI大模型与碳足迹评估相结合,可以提供更精确、更快速的碳排放量计算,优化减排策略,并促进可持续发展目标的实现。

贾贾的博客 3944

《iOS之一起进大厂》系列-秒杀面试官的RunLoop底层原理面试题

Runloop是iOS面试中的必考题,不管大厂小厂都会问到。 这里包括了Runloop几乎所有的面试题,还有中肯完整的答案解释。

空杯子 1153

【2019暑期】【PAT甲级】1154 Vertex Coloring (25 分)

这道题的题意没看懂,看了解析才勉强懂 题意就是先输入的这些是一个边的两个端点 第二个输入的是每个点的颜色 要做的就是判断每条边的两个点的颜色是否相同,不相同就输出一共有的颜色种类 用set进行颜色的筛选 用结构体存储节点,直接判断 错误的点再记得区分哪里用m,n,不要混 #include <cstdio> #include <cstdlib> #include <al...

咸鱼之井的博客 326

Fast-LIO2轮速计融合实战:打滑检测与协方差调参避坑指南

多传感器融合是提升移动机器人定位鲁棒性的关键手段。在激光雷达与惯性测量单元(IMU)紧耦合的基础上,加入轮式编码器作为额外的速度约束,能够有效抑制长走廊、重复纹理等退化场景下的漂移。其核心原理是通过运动学模型将轮速转换为机体系速度,并作为因子引入迭代误差状态卡尔曼滤波器(ESIKF)。然而,打滑现象与协方差参数设置是融合成败的关键。本文从工程实践出发,系统梳理了传感器配置、外参标定、打滑检测策略(运动学一致性、轮速自洽性)以及观测噪声协方差R与初始协方差P0的调参方法,并给出实测参数与问题排查速查表,为在F

weixin_34159110的博客 435

1154 Vertex Coloring (25 分)

1154 Vertex Coloring (25 分) A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k ...

galesaur_wcy 736

ubuntu20.4源码安装最新gcc(gcc V12.2)

Ubuntu20.4自带的gcc为V9.4.0的版本,老版本的gcc存在不支持新版本C语言规范,在配置、编译、安装应用软件或工具时,可能存在不能正确安装的问题。(比如:libpqxx-7.7.4在配置时要求c++17版本的支持,但gcc V9.4.0版本不支持c++17)。因此本文介绍ubuntu20.4的系统下载最新gcc12.2版本源码,并进行本地编译、安装。本节内容包括gcc12.2的必备库安装和gcc12.2安装两部分内容组成。

q544344318的博客 1万+

华为OD 面试手撕代码真题【判断链表是否有环】

华为OD 面试手撕代码真题【判断链表是否有环】

MISAYAONE的博客 7239

PAT 1154 Vertex Coloring (25 分)

题目传送门 这题没看太懂,只能懂大致意思,主要是根据样例来猜测题意 大致意思是给出一个图,还有已经涂好色的方案,要求任意一条边的两端不能有重复的颜色(这题在之前的真题出现过,很像)   遍历每个点,然后判断该点是不是满足条件,即判断该点和它相邻点颜色是不是冲突 然后颜色个数set解决! #include&lt;iostream&gt; #include&lt;cmath&gt; #i...

JUST CODE IT 388

QT-Creator安装教程(windows)

本文介绍了Qt的下载安装步骤:1)通过镜像源下载安装包;2)运行exe文件时使用命令行参数指定镜像地址;3)在安装过程中选择路径和自定义安装组件,包含QT5和QT6版本的详细安装说明;4)安装后可继续添加扩展包或卸载组件。重点提示了QT6必须勾选的关键组件,并提供了组件管理的操作方法。

qq_53545309的博客 3110

1154 Vertex Coloring (25 point(s))

A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k...

zclimou的博客 430

AI原生SaaS应用的自动化运维体系构建

随着ChatGPT掀起的AI原生应用浪潮,越来越多SaaS(软件即服务)产品开始以"AI优先"的方式设计——从用户交互到核心功能,都深度依赖机器学习模型(如推荐算法、智能客服)、实时数据流(如用户行为分析)和弹性算力(如大模型推理)。这类应用的运维需求与传统SaaS完全不同:传统运维像"修水管",哪里漏了补哪里;AI原生运维则像"照顾会成长的宠物",需要实时感知模型状态、数据变化和流量波动,主动调整资源。

AI天才研究院 1080

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

PAT A1154 Vertex Coloring (25point(s))

PAT A1154 Vertex Coloring 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 ...

qq_42347617的博客 179

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

1154 Vertex Coloring (25point(s)) - C语言 PAT 甲级

* 把图的所有边存起来 * 每次查询,遍历每条边,检查颜色 * 颜色的个数排序后去重

有三只土豆 232

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

【PAT】A1154 Vertex Coloring (25 point(s))

文章目录A1154 Vertex Coloring (25 point(s))Input Specification:Output Specification:Sample Input:Sample Output: A1154 Vertex Coloring (25 point(s)) A proper vertex coloring is a labeling of the graph’s ve...

Duke 239

1154 Vertex Coloring (25 point(s))

思路: 利用广度优先搜索 BFS,匹配节点与附近节点颜色是否不一样,同时需要考虑非连通图的情况,颜色的数量可以用 set 记录。 1154 Vertex Coloring (25 point(s)) Aproper vertex coloringis a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A colorin..

专栏 124

PAT(A) 1154 Vertex Coloring (25 point(s))

储存每条边,遍历每条边判断两个顶点的颜色是否相同 使用set计算颜色数 #include<bits/stdc++.h> using namespace std; int N, M, K; vector<pair<int, int>> v; vector<int> color; bool judge(void){ for(int i = 0; i < M; i++) if(color[v[i].first] == color[v

Anpotan的博客 106

PAT_甲级_1154 Vertex Coloring (25point(s)) (C++)【图的遍历/】

目录 1,题目描述 题目大意 2,思路 3,AC代码 4,解题过程 1,题目描述 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 ...

&再见萤火虫&的博客 191

1154 Vertex Coloring

A proper vertex coloring is a labeling of the graph’s vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k...

L_Aster的专栏 428

PAT甲级刷题记录——1154 Vertex Coloring (25分)

A proper vertex coloring is a labeling of the graph’s vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k-coloring. Now you are supposed to tell if a given color

一只奋斗中的本科生 273

【PAT】1154 Vertex Coloring

题目:Vertex Coloring (25 分) 题目大意:判断图中同一条边的顶点的颜色是否一致的。如果没有一致的,则输出这个图里面有多少种颜色,反之,输出No。 解题思路: 1.保存数据:将数据利用一个结构体存起来。 2.处理数据:利用color数组放每个点的颜色,利用set存放颜色。 解题代码: #include<iostream> #include<vect...

Bonstoppo 347

【PAT】1154 Vertex Coloring (25)

Aproper vertex coloringis a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at mostkcolors is called a (proper)k...

Edison_N的博客 272

Claude Code 核心架构和源码解析

⑥ 基础设施层 (Utils & Infra)⑤ 服务层 (Services)④ 工具层 (Tools)③ 核心编排层 (Core Loop & Core Subsystems)② 界面层 (UI / Ink TUI)① 入口 / 初始化层 (Entrypoints & Bootstrap)动态加载主模块共享入口preAction / action交互模式非交互 / print 模式共享服务能力共享工具能力cli.tsxCLI 入口 / fast-path / 动态 import main.tsxmcp.t

qq_40369829的博客 869
上一篇: 1153 Decode Registration Card of PAT (25 point(s))
下一篇: 1155 Heap Paths (30 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值