当前位置:网站首页>L2-025 divide and rule (25 points)
L2-025 divide and rule (25 points)
2022-06-29 10:12:00 【Momo 623】
List of articles
The title of this brush is 2021 Nian TIANTI
L2-025 Divide and rule (25 branch )
Divide and rule , It is one of the common strategies of the strategists to break each other . In the war , We hope to capture some of the enemy's cities first , Leave the rest of the city alone , Then break them separately . To this end, the staff has provided a number of strike programs . Please write a program for this question , Judge the feasibility of each plan .
Input format :
Enter two positive integers on the first line N and M( Not more than 10 000), Number of enemy cities ( So the default city is from 1 To N Number ) And the number of roads connecting the two cities . And then M That's ok , Each line gives the number of the two cities connected by a road , Separated by a space . After the city information, give a series of plans of the staff , It's a positive integer K (≤ 100) And then K Line plan , Each line is given in the following format :
Np v[1] v[2] ... v[Np]
among Np It's the number of cities planned to be conquered in this plan , Later series v[i] It's the number of the planned city .
Output format :
For each package , Output if possible YES, Otherwise output NO.
sample input :
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
sample output :
NO
YES
YES
NO
NO
Answer key
Just need to beat the point Mark it
Then traverse 1…N Again , Look at their neighbors , If there are some adjacent points, you can go .
That is, this point can go to the next . So no
#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;
}
边栏推荐
猜你喜欢
随机推荐
L2-3 这是二叉搜索树吗?-题解超精彩哦
L2-025 分而治之 (25 分)
SymPy Tutorial(译)
任务调度器之Azkaban的使用
Memory layout of JVM objects
Leetcode MySQL database topic 180
HDU 6778 Car (分组枚举-->状压 dp)
2019.11.17训练总结
A method of creating easy to manage and maintain thread by C language
leetcode MYSQL数据库题目180
Dynamic linking of virtual machine stack of JVM
L2-031 深入虎穴 (25 分)
Force deduction 85 question maximum rectangle
Codeforces Round #659 (Div. 2)
2019icpc上海区域赛赛后总结
Flutter 基础组件之 GridView
山科 的C语言2018练习题(电信)
Sixteen system counter and flow lamp
Pipeline details of IPC (interprocess communication)
Flutter 基础组件之 Image









