LightOJ 1009 Back to Underworld
来源:互联网 发布:蝴蝶标本价格淘宝 编辑:程序博客网 时间:2024/05/21 04:19
贪心+搜索
#include <bits/stdc++.h>using namespace std;int fa[20005];vector<int> g[20005];int bfs(int start){ int cnt[2] = {0}; queue<int> q; q.push(start); fa[start] = 0; cnt[0]++; while(!q.empty()) { int p = q.front(); q.pop(); for(int i = 0; i < g[p].size(); i++) { int k = g[p][i]; if(fa[k] == -1) q.push(k), fa[k] = fa[p]^1, cnt[fa[k]]++; } } return max(cnt[0], cnt[1]);}int main(){ int T; scanf("%d", &T); for(int ca = 1; ca <= T; ca++) { for(int i = 1; i <= 20000; i++) g[i].clear(), fa[i] = 0; int n, a, b; scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d%d", &a, &b); fa[a] = fa[b] = -1; g[a].push_back(b); g[b].push_back(a); } int ans = 0; for(int i = 1; i <= 20000; i++) if(fa[i] == -1) ans += bfs(i); printf("Case %d: %d\n", ca, ans); } return 0;}
0 0
- LightOJ 1009 Back to Underworld
- Lightoj--1009--Back to Underworld(dfs)
- lightoj 1009 - Back to Underworld 【DFS】
- LightOJ 1009 Back to Underworld 搜索
- LightOJ 1009 Back to Underworld (种类并查集)
- LightOJ - 1009 Back to Underworld(二分图染色)
- 【Lightoj 1009 Back to Underworld】+ 二分图染色
- lightoj 1009 - Back to Underworld(二分图染色)
- lightoj 1009 Back to Underworld (种类并查集)
- LightOJ-1009-Back to Underworld [二分图染色]
- LightOJ - 1009 Back to Underworld (vector&dfs)好题 判断两个阵营中最多人数
- Light OJ 1009 - Back to Underworld
- Light 1009 - Back to Underworld (dfs)
- Back to Underworld
- Back to Underworld
- lightoj1009 - Back to Underworld【dfs】
- 1009 - Back to Underworld(二分图染色)
- LOJ 1009 - Back to Underworld(二分图染色)
- iOS性能调优
- java进阶(五)------springMVC---springMVC+Hibernate+maven完整搭建运行步骤
- 布局和定位
- Android之获取屏幕和视图高和宽
- 域对象——ServletContext及应用
- LightOJ 1009 Back to Underworld
- [POJ 3468] A Simple Problem with Integers Splay树
- listview回滚到顶部
- com.android.dex.DexIndexOverflowException: Cannot merge new index 66299 into a non-jumbo instruction
- SQL基础知识1
- 数据结构—图
- python 编码方式总结
- RGW中的请求的认证过程
- Android之简易音乐播发器