UVA-11080 Place the Guards(二分图染色)
来源:互联网 发布:怎样做网络宣传 编辑:程序博客网 时间:2024/05/22 03:13
UVA-11080
题意:用最少的士兵看守每条街道,但不可以相邻。
//代码参考自,,,#include<iostream>#include<cstdio>#include<cstring>#include<vector>using namespace std;const int maxn = 230;int n , m , c[maxn];vector<int> G[maxn];int color_now , color_all;bool dfs(int u){ color_all++; if(c[u]==1) color_now++; for(int i = 0;i < G[u].size();i++) { int v = G[u][i]; if(c[v] == c[u]) return false; if(c[v] == 3-c[u]) continue; c[v] = 3 - c[u]; if(!dfs(v)) return false; } return true;}int main(){ int t; cin>>t; while(t--) { cin >> n >> m; for(int i = 0;i < n;i++) G[i].clear(); while(m--) { int a , b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } memset(c, 0, sizeof(c)); int res = 0; for(int i = 0;i < n;i++) if(!c[i]) { color_all = color_now = 0; c[i] = 1; if(!dfs(i)) { res = -1; break; } res += max(min(color_now, color_all-color_now), 1); } cout<< res <<endl; } return 0;}
0 0
- uva 11080 - Place the Guards(二分图染色)
- UVA-11080 Place the Guards(二分图染色)
- UVA11080- Place the Guards(二分图染色)
- (beginer) DFS (二分图判定) UVA 11080 Place the Guards
- UVA 11080 - Place the Guards(二分图判定)
- UVA11080- Place the Guards-(二分图染色)-dfs
- UVa 11080 Place the Guards
- UVA11080 Place the Guards
- uva 1335 - Beijing Guards(二分)
- uva 1335 Beijing Guards(二分)
- uva 1335 - Beijing Guards(二分)
- zoj 1654 Place the Robots (二分图匹配)
- ZOJ1654-Place the Robots(二分图匹配)
- Uva 1335 Beijing Guards 解题报告(策略+二分)
- ZJU 1654 Place the Robots(二分图)
- ZOJ1654 place the robots(二分图匹配)
- ZOJ1654 Place the Robots (二分图匹配)
- UVA - 11396 Claw Decomposition(二分图染色)
- iOS基础呀
- iOS UIWebView 自定义 UserAgent
- android app在腾讯开放平台认领应用给空白包签名
- jquery效果
- 优秀代码的格式准则
- UVA-11080 Place the Guards(二分图染色)
- Java中堆内存和栈内存详解
- 011/12/20 令人眩晕的RS232 DB9 公母头和交叉直连
- 不用sdk实现分享多张本地图片功能
- Redis与Memcached的区别
- Retrofit Token过期自动刷新并重新请求接口
- 阿里秒级android增量编译工具freeLine的使用入门
- Url参数中出现+、空格、=、%、&、#等字符的解决办法
- 关于RPC