HDU-3018-欧拉回路
2015-12-13 20:55
302 查看
题意:一笔画。。问最少几笔能画完。
如果是个欧拉回路一笔就可以完成,如果是个其它连通集,要根据这个集合的奇度数而定,笔划数=奇度数/2,用并查集来判断有多少个连通集,然后用vector来存这些连通集,通过判断度数是奇偶性来确定是否为欧拉回路;总之笔划数 = 奇度数/2 + 欧拉回路数
如果是个欧拉回路一笔就可以完成,如果是个其它连通集,要根据这个集合的奇度数而定,笔划数=奇度数/2,用并查集来判断有多少个连通集,然后用vector来存这些连通集,通过判断度数是奇偶性来确定是否为欧拉回路;总之笔划数 = 奇度数/2 + 欧拉回路数
// // main.cpp // hdu-3018-欧拉回路 // // Created by wuweiyang on 12/13/15. // Copyright © 2015 吴伟阳我. All rights reserved. // #include <iostream> #include <cstdio> #include <vector> #include <queue> #include <string> #include <string.h> #include <algorithm> using namespace std; #define maxn 100005 vector<int>V; int deg[maxn] ,odd[maxn],vis[maxn],father[maxn]; int findFather(int x){ while (x!=father[x]) { x=father[x]; } return x; } void Merge(int a,int b){ father[b]=a; } int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF){ V.clear(); for(int i=1;i<=n;i++){ father[i] = i; deg[i]=odd[i]=vis[i]=0; } for(int i=0;i<m;i++){ int a,b; scanf("%d%d",&a,&b); int fa = findFather(a); int fb = findFather(b); deg[a]++;deg[b]++; if(fa!=fb)Merge(fa,fb); } for(int i=1;i<=n;i++) { int f = findFather(i); if(!vis[f]){V.push_back(f); vis[f]=1; } if(deg[i]&1){ odd[f]++; } } int sum = 0; for(int i=0;i<V.size();i++) { if(deg[V[i]]==0)continue; if(odd[V[i]]==0)sum++; else sum+=odd[V[i]]/2; } printf("%d\n",sum); } return 0; }
相关文章推荐
- 欧拉回路的判定
- USACO/fence 3.3.1 欧拉回路
- 浙江大学ACM俱乐部 2029:欧拉回路
- poj1300 door man
- Ant Trip
- poj_2513
- UVA 10129 Play on Words
- UVa10129 判断有向图中是否存在欧拉回路
- Door Man——单笔画关门
- HDU 3018 Ant Trip
- POJ 1386 Play on Words
- POJ 2230 Watchcow
- DFS应用——寻找欧拉回路
- 例题5.3 项链 UVa10054
- UVA Play On Words 10129
- hdoj 1878 欧拉回路
- POJ1300(欧拉回路)
- poj1637Sightseeing tour(混合图欧拉回路)
- POJ 1041 John's trip (欧拉回路)
- POJ 2230 Watchcow (欧拉回路)