当前位置:网站首页>重返天梯-L2-025 分而治之 (25 分)
重返天梯-L2-025 分而治之 (25 分)
2022-04-22 21:05:00 【CodeSlogan】
题目分析
分而治之,各个击破是兵家常用的策略之一。在战争中,我们希望首先攻下敌方的部分城市,使其剩余的城市变成孤立无援,然后再分头各个击破。为此参谋部提供了若干打击方案。本题就请你编写程序,判断每个方案的可行性。
原题链接
简言之,就是给定顶点及部分边,构成图。
随后再给出几组的顶点,问删掉这些顶点,图中是否就没有边存在
边存在首先想到用度d[]表示,只要有一个顶点的度大于0,此方案就不通过
N 和 M(均不超过10 000)的数据范围巨大,无法直接用数组来存储图,会有两个测试点无法通过。因此选择用vector,存储有效边,这样就节约了遍历不存在边的时间
C++
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
vector<int> g[N]; // 存图,避免超时情况
int d[N], backup[N]; // 存储顶点的度
int n, m;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
d[a]++, d[b]++;
}
int k;
cin >> k;
while (k--) {
memcpy(backup, d, sizeof d);
int np;
cin >> np;
for (int i = 0; i < np; i++) {
int x;
cin >> x;
for (int j = 0; j < g[x].size(); j++) {
d[x]--;
d[g[x][j]]--;
}
}
bool flag = true;
for (int i = 1; i <= n; i++) {
if (d[i] > 0) {
flag = false;
break;
}
}
if (flag) puts("YES");
else puts("NO");
memcpy(d, backup, sizeof d);
}
return 0;
}
版权声明
本文为[CodeSlogan]所创,转载请带上原文链接,感谢
https://blog.csdn.net/comscience/article/details/124351266
边栏推荐
- jmeter整套资料
- 第一章 虚拟现实技术概论
- LeetCode-238-除自身以外数组的乘积
- 对Swin-T中SW-MSA的一些理解
- Confidence interval and interval estimation
- Lizard book learning Day1 - overview of machine learning
- 2022年G3锅炉水处理国家题库及在线模拟考试
- Selenium_Webdriver视频自动化脚本分享
- Introduction to dynamic programming of leetcode learning plan day1,2 (4 questions in total)
- nodejs笔记2
猜你喜欢

基于SEIR模型的传染病预测软件开发

Basic use and principle of Minio
Reprint: the development direction of programmers

UnityShader入门精要——素描效果渲染

Four things we cannot do in media operation
![[200 opencv routines of youcans] 160 Otsu method of image processing](/img/f1/8977310721848e68a5d03faf0e8ae4.png)
[200 opencv routines of youcans] 160 Otsu method of image processing

Lenovo computer housekeeper graphic introduction: how to download Lenovo computer housekeeper?

基于PAOGD的角色动画基础设计
![[interview ordinary people vs Expert Series] please talk about the network quadruple](/img/66/e83bf24095b506a8de68166d7b3bec.png)
[interview ordinary people vs Expert Series] please talk about the network quadruple

第一章 虚拟现实技术概论
随机推荐
Reprint: the development direction of programmers
buuctf-[Flask]SSTI
WampServer 搭建本地服务器及 XSS 基本原理和初步实践(一)
面试官宁愿要刚刚毕业工作1年的我小弟,也不要工作5年的我,年薪25w
站长工具大全-站长软件网站-站长工具网站-站长必备工具免费
OpenVX-将Image文件[pgm格式]读写为vx_image对象,以及写操作
MySQL 进阶 触发器 -- 触发器介绍、触发器语法、触发器案例
Webmaster Tools - Webmaster software website - Webmaster Tools website - Webmaster essential tools free
Nodejs notes 5
基于OpenGL的贪吃蛇游戏设计与实现
OpenVX 的 立即模式(immediate mode)和图模式(graph mode)和示例讲解
TC 结构管理器 - 打包 解包
基于SEIR模型的传染病预测软件开发
DSPACE simulates simple accident scene
TC fabric manager - packaging and unpacking
QT QString踩坑
Botu PLC user defined data type
Application value of smart agriculture app software
【雷达】模拟合成孔径雷达(SAR)的点目标仿真
Redis's key and value best practices