Ural 1320. Graph Decomposition(并查集,连通分支边数)
来源:互联网 发布:卡拉瓦乔 知乎 编辑:程序博客网 时间:2024/05/18 18:55
题意:一个图,每次删掉相邻的两条边,问能否把全部的边删完。
解法:若图的每个连通分量都有偶数个边就输出1,否则输出0;
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int parent[10000],depth[10000];void Make_Set(int x){ parent[x] = x; depth[x] = 0;}int Find(int x){ if(parent[x] != x) parent[x] = Find(parent[x]); return parent[x];}void Union(int u, int v){ u = Find(u); v = Find(v); if(u == v) return; if(depth[u] < depth[v]){ parent[u] = v; }else{ parent[v] = u; if(depth[u] == depth[v]) ++depth[u]; }}int main(){ int u,v,N = 0,deg[10000]; memset(deg,0,sizeof(deg)); for(int i = 0;i < 10000;++i) Make_Set(i); while(scanf("%d %d",&u,&v) == 2){ N = max(N,max(u,v)); --u; --v; Union(u,v); ++deg[u]; ++deg[v]; } int cont[10000]; memset(cont,0,sizeof(cont)); for(int i = 0;i < N;++i) cont[Find(i)] += deg[i]; bool odds = false; for(int i = 0;i < N;++i) if(cont[i] & 2) odds = true; if(odds) puts("0"); else puts("1"); return 0;}
- Ural 1320. Graph Decomposition(并查集,连通分支边数)
- URAL 1320 Graph Decomposition
- Ural 1003 Parity(并查集)
- Rikka with Graph(并查集)
- hihocoder1629:Graph (分块+并查集)
- 判断连通图(并查集 )
- 判断连通图(并查集 )
- 连通分量个数(连通分量_并查集)
- 强连通块数(深搜实现+并查集实现)
- poj1733 & Ural 1003 Parity Game (hash+并查集 )
- URAL 1982. Electrification Plan(并查集)
- Pilot Work Experience (URAL 1888 并查集+floyd)
- Ural 1671. Anansi's Cobweb(并查集)
- [容易] 并查集的优雅实现(实例:求无向图最大连通块结点数)
- LA 5031 Graph and Queries (Treap + 并查集)
- Graph Connectivity UVA, 459(并查集)
- HDOJ 题目Graph’s Cycle Component(并查集)
- HDU 5631 Rikka with Graph(并查集)
- 【解决】yum 安装 出错 Error: Protected multilib versions:
- 用powerDesigner生成数据库时_用列名称代替注释
- HTML浏览器中doctype的小常识解析
- 子类重写父类注意事项 java
- 添加自己的应用程序到右键菜单
- Ural 1320. Graph Decomposition(并查集,连通分支边数)
- IOS高级开发~Runtime(二)
- C++ 之高效使用STL(再也不用傻傻地写二分了)
- C语言--共用体
- 参数宏
- poj 1364
- AC自动机
- Linux上的free命令详解
- 创建一个简单的 eclipse+android+maven 工程