当前位置:网站首页>L2-013 red alarm (25 points)
L2-013 red alarm (25 points)
2022-04-21 12:53:00 【NEFU AB-IN】
Powered by:NEFU AB-IN
List of articles
L2-013 Red Alert (25 branch )
-
The question
It's very important to maintain connectivity between cities in the war . This question asks you to write an alarm program , When the loss of a city causes the country to be divided into multiple disconnected areas , Just a red alert . Be careful : If the country is not fully connected , It's divided k Regions , The loss of one city does not change the connectivity between other cities , Then don't alarm .
-
Ideas
DFS Just find the connected block , If captured , It means it has been marked before , Count the number of connected blocks before and after the attack
Complexity O ( n k m ) O(nkm) O(nkm) -
Code
/* * @Author: NEFU AB-IN * @Date: 2022-04-21 10:16:41 * @FilePath: \ACM\GPLT\L2-013.CPP * @LastEditTime: 2022-04-21 10:29:52 */ #include <bits/stdc++.h> using namespace std; #define int long long #define MP make_pair #define SZ(X) ((int)(X).size()) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define DEBUG(X) cout << #X << ": " << X << endl; typedef pair<int, int> PII; const int INF = 0x3f3f3f3f; const int N = 510; vector<int> g[N]; int n, m, k, st[N]; void dfs(int u, int fa) { for (auto v : g[u]) { if (fa == v || st[v]) continue; st[v] = 1; dfs(v, u); } } signed main() { IOS; cin >> n >> m; for (int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } cin >> k; vector<int> vis; for (int i = 1; i <= k; ++i) { int x, cnt1 = 0, cnt2 = 0; cin >> x; memset(st, 0, sizeof st); for (auto u : vis) st[u] = 1; for (int i = 0; i < n; ++i) { if (!st[i]) { dfs(i, -1); cnt1 += 1; } } vis.push_back(x); memset(st, 0, sizeof st); for (auto u : vis) st[u] = 1; for (int i = 0; i < n; ++i) { if (!st[i]) { dfs(i, -1); cnt2 += 1; } } if (cnt2 > cnt1) printf("Red Alert: City %lld is lost!\n", x); else printf("City %lld is lost.\n", x); } if (n == k) printf("Game Over."); return 0; }
版权声明
本文为[NEFU AB-IN]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211251306465.html
边栏推荐
- Revit secondary development - creating elevation (phase 8)
- 选择排序法
- Validation data validation annotation
- Revit二次开发——创建楼板(第十二期)
- 【论文学习】YOLO v2
- L2-013 红色警报 (25 分)
- [SQL] sql19 finds the last of all employees_ Name and first_ Name and corresponding Dept_ name
- Master slave replication -- 03 -- synchronization data consistency
- 4年Android开发13K,刷完这份1307页Android-面试全套真题解析,跳槽涨薪15K
- 挖财的证券账户怎么开户?在券商开户是不是比较安全一些?
猜你喜欢

业内视频超分辨率新标杆,快手&大连理工研究登上CVPR 2022
AES自动生成base64密钥加密解密

2022年监理工程师考试基本理论与相关法规练习题及答案

4 years of Android development 13K, completed this 1307 page Android interview full set of real problem analysis, job hopping and salary increase 15K

上个网课都能被AI分析“在走神”,英特尔这个情绪检测AI火了

STM32Cubemx安装

Title and answer of G3 boiler water treatment certificate in 2022

框架的灵魂------反射

mysql数据库操作语句练习

A comprehensive understanding of static code analysis
随机推荐
2022语言与智能技术竞赛再升级,推出NLP四大前沿任务
Call for Papers | IEEE/IAPR IJCB 2022 会议
SM国密学习
Creating plug-in panel for Revit secondary development (issue 15)
Convert m3u8 format to MP4 through fmpeg
通信滑动窗口
Operation of simulated examination platform of test question bank for operation certificate of safety management personnel of hazardous chemical business units in 2022
框架的灵魂------反射
Algorithem_Merge Two Binary Trees
选择排序法
Redis frequently asked questions
利用Cisco配置VRRP(虚拟路由器冗余协议)
挖财的证券账户怎么开户?在券商开户是不是比较安全一些?
自媒体如何打造爆文,提升阅读量
二叉树遍历系列02-Morris遍历
AES自动生成base64密钥加密解密
斐波那契数列
STM32Cubemx安装
[source code analysis] encoding in style: a stylegan encoder for image to image translation
Revit二次开发之创建族实例(第十三期)