当前位置:网站首页>L2-025 分而治之 (25 分)
L2-025 分而治之 (25 分)
2022-06-29 09:23:00 【陌陌623】
本次刷题为2021年天梯
L2-025 分而治之 (25 分)
分而治之,各个击破是兵家常用的策略之一。在战争中,我们希望首先攻下敌方的部分城市,使其剩余的城市变成孤立无援,然后再分头各个击破。为此参谋部提供了若干打击方案。本题就请你编写程序,判断每个方案的可行性。
输入格式:
输入在第一行给出两个正整数 N 和 M(均不超过10 000),分别为敌方城市个数(于是默认城市从 1 到 N 编号)和连接两城市的通路条数。随后 M 行,每行给出一条通路所连接的两个城市的编号,其间以一个空格分隔。在城市信息之后给出参谋部的系列方案,即一个正整数 K (≤ 100)和随后的 K 行方案,每行按以下格式给出:
Np v[1] v[2] ... v[Np]
其中 Np 是该方案中计划攻下的城市数量,后面的系列 v[i] 是计划攻下的城市编号。
输出格式:
对每一套方案,如果可行就输出YES,否则输出NO。
输入样例:
10 11
8 7
6 8
4 5
8 4
8 1
1 2
1 4
9 8
9 1
1 10
2 4
5
4 10 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
题解
仅仅需要将击败的点 标注即可
然后遍历1…N一遍,看他们的邻接点,如果有的邻接点可以走。
即这个点可以走向下一个。故不行
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int n = 10005;
vector<int> v[n];
int main()
{
int N, M;
cin >> N >> M;
int x, y;
while (M--)
{
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
cin >> M;
while (M--)
{
int K;
cin >> K;
int dp[n] = {0};
for (int i = 0; i < K; i++)
cin >> x, dp[x]++;
int t = 0;
for (int i = 1; i <= N; i++)
if (!dp[i])
for (auto &e : v[i])
if (dp[e] == 0)
{
t = 1;
break;
}
printf("%s", t == 0 ? "YES\n" : "NO\n");
}
return 0;
}
边栏推荐
- 指针函数和函数指针
- Alternative implementation of Scrollview pull-down header amplification
- Application of keil5 integrated development environment for single chip microcomputer
- C语言实现一种创建易管理易维护线程的方法
- Flutter 基础组件之 Text
- Constructing SQL statements by sprintf() function in C language
- 点在多边形内外的判断
- 分布式和集群分不清,我们讲讲两个厨子炒菜的故事
- Codeforces Round #659 (Div. 2)
- 语言特性
猜你喜欢

Container of the basic component of the flutter

A 2.5D Cancer Segmentation for MRI Images Based on U-Net

The Stones Game【取石子博弈 & 思维】

RecyclerView 通用适配器封装

The collapsing "2.3 * 10 = 22" produced by multiplying float and int

JVM之虚拟机栈之动态链接

自定义控件之侧滑关闭 Activity 控件

GridView of basic component of shutter

点在多边形内外的判断

力扣94二叉树的中序遍历
随机推荐
Sixteen system counter and flow lamp
Leetcode MySQL database topic 177
Introduction to intranet penetration tool FRP
float 与 int 相乘产生的令人崩溃的“ 2.3 * 10 = 22 ”
Flutter 基础组件之 Image
【51nod 1215】数组的宽度
JVM之方法返回地址
Gmail: how to quickly read all messages
Caused by: org.apache.xerces.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8
The Stones Game【取石子博弈 & 思维】
HDU 4578 Transformation(线段树+有技巧的懒标记下放)
Pointer functions and function pointers
任务调度器之Azkaban的使用
leetcode MYSQL数据库题目177
PHP内存马技术研究与查杀方法总结
F5 BIG-IP iControl REST命令执行(CVE-2022-1388)
ImageView图片填充问题
nacos注册中心集群
信号作品:时变和时不变
2019.10.27训练总结