【欧拉回路】toj 1004 John's trip
来源:互联网 发布:村上春树知乎 编辑:程序博客网 时间:2024/05/18 00:02
题目大意,给m个顶点,n条边的无向图,问是否存在欧拉回路。
细节1:起点是第一行数据中两个端点较小的那个,不一定是1号顶点。
细节2:要求输出的欧拉回路的边序列字典序最小。
细节处理:起点不要搞错了,注意输入格式。输出字典序可以简单排序处理,点数非常少,可以瞎搞。。。
/* * 欧拉回路 */#include <cstdio>#include <cstring>#include <vector>#include <stack>#include <algorithm>using namespace std;const int MAX = 2048;const int MAX_V = 64;struct Edge {int to;int eid;bool operator<(const Edge& B)const {return eid < B.eid;}};vector<Edge> G[MAX_V];bool vis[MAX];stack<int> S;int deg[MAX_V];void dfs(int u) {for (vector<Edge>::iterator it = G[u].begin();it != G[u].end(); ++it) {if (vis[it->eid]) continue;vis[it->eid] = true;dfs(it->to);S.push(it->eid);}}bool eular(int start) {for (int i = 0; i < MAX_V; ++i) {if (deg[i] & 1) {//printf("node %d has deg %d\n", i, deg[i]);return false;}}memset(vis, false, sizeof(vis));while (!S.empty()) S.pop(); //any casefor (int i = 1; i < MAX_V; ++i) {sort(G[i].begin(), G[i].end());}dfs(start);return true;}int main() {int u, v, e;while (~scanf(" %d %d", &u, &v) && u) {for (int i = 0; i < MAX_V; ++i) G[i].clear();memset(deg, 0, sizeof(deg));int start = min(u, v);while (~scanf(" %d", &e)) {G[u].push_back((struct Edge){v, e});G[v].push_back((struct Edge){u, e});++deg[u];++deg[v];scanf(" %d %d", &u, &v);if (u == 0) break;}if (eular(start)) {printf("%d", S.top());S.pop();while (!S.empty()) {printf(" %d", S.top());S.pop();}puts("\n");} else {puts("Round trip does not exist.\n");}}return 0;}
不水了不水了,窝要开始按目录学习了...话说我想装好linux再专心码代码的啊啊啊啊啊...
0 0
- 【欧拉回路】toj 1004 John's trip
- poj1041 John's trip (欧拉回路)
- POJ 1041 John's trip (欧拉回路)
- John's trip 欧拉回路输出路径
- poj 1041 John's trip(欧拉回路)
- POJ 1041 John's trip(欧拉回路+输出路径)
- poj 1041 John's trip 欧拉回路
- POJ 1041 John's trip (欧拉回路)
- POJ 1041 John's trip(欧拉回路)
- POJ 1041 John's trip(欧拉回路)
- POJ1041 John's trip 欧拉回路路径查找
- POJ 1041 John's trip(欧拉回路)
- POJ 1041 - John's trip(欧拉回路)
- poj1041 John's trip(欧拉回路+输出路径)
- 欧拉回路——John's trip ( POJ 1041 )
- POJ1041 John's trip(欧拉回路+打印路径)
- POJ 1041 John's trip Euler欧拉回路判定和求回路
- poj 1041 John's trip(欧拉回路入门题)
- <td colspan=""> <span style=""></span> </td>
- 处理MYSQL主从库数据不一致的问题【Slave_SQL_Running: No】
- 关于Code Review的那些事
- 基于lucene的案例开发:ClassUtil & CharsetUtil
- Mysql 存储过程
- 【欧拉回路】toj 1004 John's trip
- Android动画之仿美团加载数据等待时,小人奔跑进度动画对话框(附顺丰快递员奔跑效果)
- 在 Hibernate4 中使用HibernateDaoSupport
- Android联系人存储结构
- poj-2031 Building a Space Statio
- Java:对象的强、软、弱和虚引用
- 单点登录CAS-Demo
- 应用程序无法启动,因为应用程序的并行配置不正确。
- SVD的一些理解