当前位置:网站首页>UVA 11080 – place the guards
UVA 11080 – place the guards
2022-07-07 21:04:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
UVA 11080 – Place the Guards
The question : Some cities . There are roads between them , Now we're going to place guards , The guard can watch the edge around the current point , There can only be one guard on one side , Ask if there is a plan , Suppose there are at least a few guards
Ideas : Bipartite graph decision , Record the number of white dots and black dots in the determination process , The small one is the number to be placed , Note that the assumption is 0, Then it should be plus 1
Code :
#include <cstdio>#include <cstring>#include <vector>using namespace std;const int N = 205;int color[N];vector<int> g[N];int b, w;int bipartite(int u) { if (color[u] == 1) b++; if (color[u] == 2) w++; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (color[u] == color[v]) return false; if (!color[v]) { color[v] = 3 - color[u]; if (!bipartite(v)) return false; } } return true;}int t, n, m;int solve() { int ans = 0; for (int i = 0; i < n; i++) { if (!color[i]) { color[i] = 1; b = w = 0; if (!bipartite(i)) return -1; ans += max(1, min(b, w)); } } return ans;}int main() { scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { g[i].clear(); color[i] = 0; } int u, v; while (m--) { scanf("%d%d", &u, &v); g[u].push_back(v); g[v].push_back(u); } printf("%d\n", solve()); } return 0;}
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116454.html Link to the original text :https://javaforall.cn
边栏推荐
- Implement secondary index with Gaussian redis
- Le capital - investissement est - il légal en Chine? C'est sûr?
- Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
- 开户还得用身份证银行卡安全吗,我是小白不懂
- 恶魔奶爸 A1 语音听力初挑战
- How to meet the dual needs of security and confidentiality of medical devices?
- DataTable数据转换为实体
- HOJ 2245 浮游三角胞(数学啊 )
- Codeforces 474 F. Ant colony
- 华泰证券可以做到万一佣金吗,万一开户安全嘛
猜你喜欢
ISO 26262 - 基于需求测试以外的考虑因素
Tensorflow2.x下如何运行1.x的代码
Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)
【C语言】指针进阶---指针你真的学懂了吗?
上海交大最新《标签高效深度分割》研究进展综述,全面阐述无监督、粗监督、不完全监督和噪声监督的深度分割方法
Tensorflow2. How to run under x 1 Code of X
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
Intelligent software analysis platform embold
使用枚举实现英文转盲文
CodeSonar网络研讨会
随机推荐
I wrote a markdown command line gadget, hoping to improve the efficiency of sending documents by garden friends!
Write a jump table
Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
Codeforces round 296 (Div. 2) A. playing with paper[easy to understand]
awk处理JSON处理
Codeforces 474 F. Ant colony
Cantata9.0 | new features
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
Flask1.1.4 Werkzeug1.0.1 源码分析:路由
SQL注入报错注入函数图文详解
刚开户的能买什么股票呢?炒股账户安全吗
[matrix multiplication] [noi 2012] [cogs963] random number generator
You want to kill a port process, but you can't find it in the service list. You can find this process and kill it through the command line to reduce restarting the computer and find the root cause of
Intelligent transportation is full of vitality. What will happen in the future? [easy to understand]
Mongodb learn from simple to deep
[concept of network principle]
华泰证券可以做到万一佣金吗,万一开户安全嘛
Nebula Importer 数据导入实践