当前位置:网站首页>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
边栏推荐
- How to choose financial products? Novice doesn't know anything
- Mysql子查询关键字的使用方式(exists)
- Mahout-Pearson correlation的实现
- [function recursion] do you know all five classic examples of simple recursion?
- 恶魔奶爸 B1 听力最后壁垒,一鼓作气突破
- AADL inspector fault tree safety analysis module
- 恶魔奶爸 B3 少量泛读,完成两万词汇量+
- Unity3d 4.3.4f1执行项目
- Jetty:配置连接器[通俗易懂]
- I have to use my ID card to open an account. Is the bank card safe? I don't understand it
猜你喜欢

C language helps you understand pointers from multiple perspectives (1. Character pointers 2. Array pointers and pointer arrays, array parameter passing and pointer parameter passing 3. Function point

Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation

OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验

Apifox interface integrated management new artifact

恶魔奶爸 B3 少量泛读,完成两万词汇量+
Mysql子查询关键字的使用方式(exists)

Mongodb learn from simple to deep

Measure the height of the building

如何满足医疗设备对安全性和保密性的双重需求?

H3C s7000/s7500e/10500 series post stack BFD detection configuration method
随机推荐
Cocos2d-x game archive [easy to understand]
Numerical method for solving optimal control problem (0) -- Definition
国家正规的股票交易app有哪些?使用安不安全
万字总结数据存储,三大知识点
【C语言】指针进阶---指针你真的学懂了吗?
智能软件分析平台Embold
Codesonar Webinar
Is private equity legal in China? Is it safe?
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
寫一下跳錶
[award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
guava多线程,futurecallback线程调用不平均
npm uninstall和rm直接删除的区别
Unity3d 4.3.4f1执行项目
Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
How to meet the dual needs of security and confidentiality of medical devices?
CodeSonar如何帮助无人机查找软件缺陷?
部署、收回和删除解决方式—-STSADM和PowerShell「建议收藏」
静态测试工具
Introduction to referer and referer policy