当前位置:网站首页>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
边栏推荐
- Flask1.1.4 werkzeug1.0.1 source code analysis: Routing
- 如何挑选基金产品?2022年7月份适合买什么基金?
- H3C s7000/s7500e/10500 series post stack BFD detection configuration method
- Codesonar enhances software reliability through innovative static analysis
- SQL注入报错注入函数图文详解
- Flask1.1.4 Werkzeug1.0.1 源码分析:路由
- Codeforces 474 F. Ant colony
- UVA 11080 – Place the Guards(二分图判定)
- MySQL约束之默认约束default与零填充约束zerofill
- Mongodb learn from simple to deep
猜你喜欢

解决使用uni-app MediaError MediaError ErrorCode -5

恶魔奶爸 B3 少量泛读,完成两万词汇量+
![[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System](/img/76/b725788272ba2dcdf866b28cbcc897.jpg)
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System

【OpenCV 例程200篇】223. 特征提取之多边形拟合(cv.approxPolyDP)

神兵利器——敏感文件发现工具

I Basic concepts

ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your

不落人后!简单好用的低代码开发,快速搭建智慧管理信息系统

使用枚举实现英文转盲文
SQL注入报错注入函数图文详解
随机推荐
Deep learning model compression and acceleration technology (VII): mixed mode
智能交通焕发勃勃生机,未来会呈现哪些巨变?[通俗易懂]
uva 12230 – Crossing Rivers(概率)「建议收藏」
SQL注入报错注入函数图文详解
Apifox interface integrated management new artifact
上海交大最新《标签高效深度分割》研究进展综述,全面阐述无监督、粗监督、不完全监督和噪声监督的深度分割方法
easyui 日期控件清空值
Ubuntu安装mysql8遇到的问题以及详细安装过程
凌云出海记 | 赛盒&华为云:共助跨境电商行业可持续发展
恶魔奶爸 A1 语音听力初挑战
Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system
Cantata9.0 | new features
Is it safe to open an account online now? I want to know where I can open an account in Nanning now?
Object-C programming tips timer "suggestions collection"
Tensorflow2.x下如何运行1.x的代码
私募基金在中國合法嗎?安全嗎?
Is it safe to open an account of BOC shares in kainiu in 2022?
Measure the height of the building
阿里云有奖体验:如何通过ECS挂载NAS文件系统
权限不足