当前位置:网站首页>PAT 甲级 1134 顶点覆盖
PAT 甲级 1134 顶点覆盖
2022-06-10 10:19:00 【键盘奏鸣曲】
如果图中的一个顶点集合能够满足图中的每一条边都至少有一个端点在该集合内,那么这个顶点集合就是图的顶点覆盖。
现在给定一张图,以及若干个顶点集合,请你判断这些顶点集合是否是图的顶点覆盖。
输入格式
第一行包含两个整数 N 和 M,表示图中点和边的数量。接下来 M 行,每行包含两个整数 a,b,表示点 a 和点 b 之间存在一条边。
点编号 0∼N−1。
然后包含一个整数 K,表示询问的顶点集合数量。
接下来 K 行,每行描述一组询问顶点集合,格式如下:
Nv V[1] V[2] … V[Nv]
Nv 是集合中点的数量,V[i] 是点的编号。输出格式
每组询问输出一行结果,如果是顶点覆盖则输出 Yes,否则输出 No。数据范围
1≤N,M≤104,
1≤K≤100,
1≤Nv≤N
输入样例:
10 11
8 7
6 8
4 5
8 4
8 1
1 2
1 4
9 8
9 1
1 0
2 4
5
4 0 3 8 4
6 6 1 7 5 4 9
3 1 8 4
2 2 8
7 9 8 7 6 5 4 2
输出样例:
No
Yes
Yes
No
No
我的解法:
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n, m;
bool st[N];
struct Edge{
int a, b;
}E[N];
int main(){
cin >> n >> m;
for(int i = 0; i < m; i ++ ){
int a, b;
cin >> E[i].a >> E[i].b;
}
int k;
cin >> k;
while(k -- ){
int v;
cin >> v;
memset(st, 0 , sizeof st);
while(v -- ){
int node;
cin >> node;
st[node] = true;
}
int i;
for(i = 0; i < m; i ++ ){
if(st[E[i].a] == false && st[E[i].b] == false) break;
}
if(i == m) puts("Yes");
else puts("No");
}
return 0;
}收获:
遇到简单的问题,可以使用结构体数组来存图
边栏推荐
猜你喜欢

62. 不同路径-动态规划

Qchart note 1: simple linear diagram lineseries

混音器:视频会议录制不可或缺的组件

Xcode8.3.2 automatic packaging script

一个独特的简历生成器,开源了!

Axure add drop-down menu linkage

Xcode8.3.2 自动打包脚本

Dr. jiangxiaowei, a member of hpca Hall of fame, is the chief scientist of Dayu smart core

山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(十六)

协程asyncio异步编程
随机推荐
六、观察者模式
NFT铸造交易平台开发市场详情
MAC下安装MySQL+Django详细步骤
PV操作每日一题-橘子苹果问题(高阶版变式)
Multithreading implementation
dried food! Training method of machinetranslation model based on mask label smoothing
多线程实现的方式
PV操作每日一题-缓冲区问题(进阶版)
随机生成数字字母(大写)组合
How long has elapsed to show the time
mdb转换为db文件
C 12 循环队列Circular queue
2021 ciscn PWN preliminary
「诗经」主题文化数字藏品中奖名单公布
八、链模式
7、 Policy mode
Xcode8.3.2 automatic packaging script
Question bank and answers of 2022 metal and nonmetal mine hoist operation examination
9、 Delegation mode
2023 Wangdao C language training camp (binary search tree - sequential search - half search)