UVA10054 The Necklace 无向图欧拉回路+连通性
来源:互联网 发布:gymnopedie no.1 知乎 编辑:程序博客网 时间:2024/05/16 00:59
很基础的一道题,主要是学习一下如何使用并查集判断图的连通性以及无向图欧拉回路的判断
还有就是最重点的欧拉回路的输出路径问题
DFS部分是重点,先遍历,后输出
#include<bits/stdc++.h>
using namespace std;
int mp[55][55];
int rudu[60];
int father[60];
void dfs(int u)
{
for(int i=1;i<=50;i++)
if(mp[u][i])
{
mp[u][i]--;mp[i][u]--;
dfs(i);
printf("%d %d\n", i, u);
}
}
void init(int n)
{
for(int i=1;i<=n;i++)
father[i] = i;
}
int findd(int n)
{
return father[n] == n?n:father[n] = findd(father[n]);
}
void unionn(int u,int v)
{
father[findd(u)] = findd(v);
}
int main()
{
int i, n, a, b, temp, t, T;
scanf("%d", &T);
for(temp=1;temp<=T;temp++)
{
memset(mp, 0,sizeof(mp));
memset(rudu, 0, sizeof(rudu));
init(50);
scanf("%d", &n);
while(n--)
{
scanf("%d%d", &a, &b);
unionn(a, b);
mp[a][b]++;mp[b][a]++;
rudu[a]++;rudu[b]++;
}
printf("Case #%d\n", temp);
t=0;
for(i=1;i<=50;i++)
if(rudu[i]&&father[i] == i)
t++;
if(t!=1)
{
printf("some beads may be lost\n\n");
continue;
}
t=0;
for(i=1;i<=50;i++)
if(rudu[i]%2)
t=1;
if(t==1)
{
printf("some beads may be lost\n\n");
continue;
}
dfs(a);
printf("\n");
}
return 0;
}
- UVA10054 The Necklace 无向图欧拉回路+连通性
- UVa10054 The Necklace,无向图求欧拉回路
- UVa10054 The Necklace (欧拉回路)
- 【UVa10054】The Necklace【欧拉回路】
- UVA10054 The Necklace (输出欧拉回路)
- uva10054-The Necklace(项链)
- The Necklace UVA10054
- UVA10054 The Necklace
- UVa10054 The Necklace
- The Necklace UVA10054
- uva10054 The Necklace
- UVA10054 The Necklace
- UVA10054-The Necklace
- The Necklace UVA10054
- Uva10054 无向图打印任意欧拉回路
- uva10054 The Necklace (欧拉回路路径输出 (并查集 + DFS) || (DFS + stack))
- 无向图欧拉回路
- hdu 1878 欧拉回路 无向图连通性
- (四)spring cloud云服务
- CentOS6.5系统下RPM包安装MySQL5.6
- springmvc 不解析EL表达式的解决办法
- 人工智能之机器学习
- 【图像处理】SFR算法详解1
- UVA10054 The Necklace 无向图欧拉回路+连通性
- C语言入门第十二篇,数组练习题
- window10 删除user个人文件后anaconda navigator 无法正常启动问题解决(猜测同系列方法类似)
- jvm 内存回收finalize如何在垃圾清除前工作原理
- 关于JAVASCRIPT,17年你需要尝试这20条建议(下)
- 关于JavaScript,17年你可以尝试这20条建议(上)
- 双向 LSTM
- 一个 tflearn 情感分析小例子
- 数据库水平切分的实现原理—分库、分表、读写分离、负载均衡、主从复制