UVA 10968 - KuPellaKeS(BFS)
来源:互联网 发布:凡茜卸妆油怎么样知乎 编辑:程序博客网 时间:2024/06/05 14:38
UVA 10968 - KuPellaKeS
题目链接
题意:给定一个图,要求把这个图删掉一些边后,使得他所以有点度数为不等于0的偶数,保证图一开始最多只有最多2个奇数度数结点
思路:对于有奇数点的情况,肯定从奇数点找到到另一个奇数点,途中不能路过度数为2的点,把这些边删掉就是答案,这样就相当于求最小距离,然后注意特殊情况,就是奇数点度数为1和一开始就有度数为0的情况
代码:
#include <cstdio>#include <cstring>#include <vector>#include <queue>using namespace std;const int N = 1005;int n, m, du[N], vis[N];vector<int> g[N];void init() {memset(du, 0, sizeof(du));for (int i = 1; i <= n; i++)g[i].clear();int u, v;while (m--) {scanf("%d%d", &u, &v);du[u]++; du[v]++;g[u].push_back(v);g[v].push_back(u);}}bool solve() {int st[2], sn = 0;for (int i = 1; i <= n; i++) {if (du[i] == 1 || du[i] == 0) return false;if (du[i] % 2)st[sn++] = i;}if (sn == 0) {printf("0\n");return true;}memset(vis, -1, sizeof(vis));queue<int> Q;Q.push(st[0]);vis[st[0]] = 0;while (!Q.empty()) {int u = Q.front();if (u == st[1]) {printf("%d\n", vis[u]);return true;}Q.pop();for (int i = 0; i < g[u].size(); i++) {int v = g[u][i];if (du[v] == 2) continue;if (vis[v] != -1) continue;vis[v] = vis[u] + 1;Q.push(v);}}return false;}int main() {while (~scanf("%d%d", &n, &m) && n) {init();if (!solve()) printf("Poor Koorosh\n");}return 0;}
0 0
- UVA 10968 - KuPellaKeS(BFS)
- UVA 10968 - KuPellaKeS 【BFS】
- uva 10968 - KuPellaKeS
- (intermediate) UVA 最短路 10968 - KuPellaKeS
- uva 784(bfs)
- UVa 3721 - Islands 【bfs】
- uva 10603 倒水 bfs
- uva 10603 - Fill bfs
- uva 11624(BFS)
- uva 10047(BFS)
- UVA 11624 BFS Fire
- UVa Fire! 11624 (BFS)
- 双向BFS--Uva-11624
- UVA 10047 独轮车(BFS)
- uva 11624 - Fire! bfs
- UVa 11624 Fire! / BFS
- uva 1377 - Ruler(BFS)
- UVA 10603 - Fill BFS~
- UVA - 10916 Factstone Benchmark(数学)
- 配置ssh公钥访问oschina
- 用c语言实现单链表的逆序输出
- 编程精粹--编写高质量C语言代码(5):为子系统设防(二)
- 使用接插件需要注意的问题
- UVA 10968 - KuPellaKeS(BFS)
- pat 1057. Stack (30) 浙江大学复试上机最后一题
- 第三方苹果开发库之ASIHTTPRequest
- android ListView 滑动删除Item的代码分析
- Beyond bags of features: Spatial Pyramid Matching 文章的笔记
- 最简单的android开发环境的搭建
- asp.net “非静态字段、方法或属性’System.Web.UI.Page.Response.get‘要求对象引用”
- Design the city - ZOJ 3195 LCA
- USRP2 FPGA debugging