当前位置:网站首页>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
边栏推荐
- Dachang classic pointer written test questions
- How to choose fund products? What fund is suitable to buy in July 2022?
- MinGW MinGW-w64 TDM-GCC等工具链之间的差别与联系「建议收藏」
- 特征生成
- Small guide for rapid formation of manipulator (12): inverse kinematics analysis
- Flask1.1.4 werkzeug1.0.1 source code analysis: Routing
- ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- CodeSonar网络研讨会
- 使用高斯Redis实现二级索引
- 目标:不排斥 yaml 语法。争取快速上手
猜你喜欢
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
不落人后!简单好用的低代码开发,快速搭建智慧管理信息系统
嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]
恶魔奶爸 B3 少量泛读,完成两万词汇量+
Codesonar enhances software reliability through innovative static analysis
程序猿赚的那点钱算个P啊!
Nebula Importer 数据导入实践
Helix QAC 2020.2新版静态测试工具,最大限度扩展了标准合规性的覆盖范围
Mysql子查询关键字的使用方式(exists)
智能软件分析平台Embold
随机推荐
Update iteration summary of target detection based on deep learning (continuous update ing)
如何满足医疗设备对安全性和保密性的双重需求?
How to meet the dual needs of security and confidentiality of medical devices?
Dachang classic pointer written test questions
Ubuntu安装mysql8遇到的问题以及详细安装过程
阿里云有奖体验:如何通过ECS挂载NAS文件系统
上海交大最新《标签高效深度分割》研究进展综述,全面阐述无监督、粗监督、不完全监督和噪声监督的深度分割方法
I Basic concepts
How to meet the dual needs of security and confidentiality of medical devices?
Mysql子查询关键字的使用方式(exists)
Klocwork 代码静态分析工具
使用枚举实现英文转盲文
恶魔奶爸 C
Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
恶魔奶爸 B3 少量泛读,完成两万词汇量+
恶魔奶爸 B1 听力最后壁垒,一鼓作气突破
margin 等高布局
最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化