uva10054-The Necklace(项链)
来源:互联网 发布:php用逗号拼接字符串 编辑:程序博客网 时间:2024/05/16 17:36
图的判断欧拉回路+输出路径
回路的判定要从度和连通两方面判定(但此题测试数据水的很,我只写了个度的判定)
路径输出一定要后序压栈输出(就是后序遍历一下)先序不行的哦!!!
举个反例
自己先走路径1,再走路径2,先序和后序分别试一下,差不多就知道为什么要后序输出路径了
我的代码如下:
#include <stdio.h>#include <string.h>int G[55][55];int du[55];void dfs(int x){ for(int i=50;i>=0;i--) if(G[x][i]) { G[x][i]--; G[i][x]--; dfs(i); printf("%d %d\n",i,x); }}void output(){ for(int i = 1; i <= 50; i++) if(!du[i])continue; else dfs(i);}int main (){ int t, n, front, rear, flag, count= 0; scanf("%d",&t); while(t--) { memset(du,0,sizeof(du)); memset(G,0,sizeof(G)); flag = 0; scanf("%d",&n); while(n--) { scanf("%d%d",&front,&rear); du[front]++, du[rear]++; G[front][rear]++, G[rear][front]++; } printf("Case #%d\n", ++count); for(int i = 1; i <= 50; i++) if(du[i]%2){puts("some beads may be lost"); flag = 1; break;} if(!flag)output(); if(t)puts(""); } return 0;
- 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 The Necklace,无向图求欧拉回路
- UVa10054 The Necklace (欧拉回路)
- 【UVa10054】The Necklace【欧拉回路】
- UVA10054 The Necklace (输出欧拉回路)
- UVA10054 The Necklace 无向图欧拉回路+连通性
- 例题5.3 项链 UVa10054
- UVa Problem 10054 The Necklace (项链)
- uva10054 The Necklace (欧拉回路路径输出 (并查集 + DFS) || (DFS + stack))
- 【SDOI2013 necklace】项链
- 【并查集入门】HDU1232——畅通工程
- java版本的escape和unescape函数
- 关于VS2008中C/C++内存泄漏的定位的方法
- 【分布式系统工程实现】如何检测一台机器是否宕机?
- opencv中自带blobtrack运行演示
- uva10054-The Necklace(项链)
- 数据类型相互转换
- 招聘中级测试工程师、开发测试工程师各一名
- lease 分布式
- SEO网络优化方法
- 50个必备的实用jQuery代码段
- CF-18D - Seller Bob(贪心+简单大数)
- Python 初体验之 最基本的if-else-while-for
- 一个字节造成的巨大性能差异——SQL Server存储结构