poj 1041 John's trip(欧拉回路入门题)
来源:互联网 发布:个性字体软件下载 编辑:程序博客网 时间:2024/05/16 16:12
经典的欧拉回路题
http://poj.org/problem?id=1041
欧拉回路:每条边经过一次且仅一次的称为欧拉回路(euler cycle, euler circuit)。
存在欧拉回路的充要条件:每个点的度数都是偶数, 且图连通。
#include "iostream"#include "stdio.h"#include "string.h"#include "algorithm"using namespace std;int G[50][2000]; //G[点][边] = 点,这样是为了能方便让边lexicographically输出bool vis[2000]; //记录访问边的情况int degree[50];int stack[2000], top;int max(int a, int b){return a > b ? a : b;}void euler(int cur, int nRoads) //cur当前访问的点{for(int i = 1; i <= nRoads; i++){if(!vis[i] && G[cur][i]) //若相邻边未访问过{vis[i] = true;euler(G[cur][i], nRoads);stack[++top] = i;}}}int main(){int x, y, z, nRoads, nPoints, start;while(scanf("%d%d", &x, &y) && x && y){nRoads = nPoints = top = 0;memset(vis, false, sizeof(vis));memset(degree, 0, sizeof(degree));memset(G, 0, sizeof(G));start = x < y ? x : y;cin >> z;nRoads = max(nRoads, z);nPoints = max(nPoints, max(x, y));G[x][z] = y;G[y][z] = x;degree[x]++; degree[y]++;while(scanf("%d%d", &x, &y) && x && y){cin >> z;nRoads = max(nRoads, z);nPoints = max(nPoints, max(x, y));G[x][z] = y;G[y][z] = x;degree[x]++; degree[y]++;}bool flag = true;for(int i = 1; i <= nPoints; i++)if(degree[i] & 1)flag = false;if(!flag)cout << "Round trip does not exist." << endl;else{euler(start, nRoads);printf("%d", stack[top]);for(int i = top - 1; i > 0; i--)printf(" %d", stack[i]);cout << endl;}}return 0;}
- 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(欧拉回路+输出路径)
- poj 1041 John's trip 欧拉回路
- POJ 1041 John's trip (欧拉回路)
- POJ 1041 John's trip(欧拉回路)
- POJ 1041 - John's trip(欧拉回路)
- 欧拉回路——John's trip ( POJ 1041 )
- POJ 1041 John's trip (在POJ首题~~经典的欧拉回路)
- POJ 1041 John's trip 欧拉回路(输出路径)
- POJ NO.1041 John's trip(字典序输出欧拉回路)
- POJ 1041 John's trip Euler欧拉回路判定和求回路
- 百题纪念之1041 John's trip(欧拉回路)
- poj1041 John's trip (欧拉回路)
- POJ 1041 - John's trip 输出欧拉回路路径边..通用做法
- How can we use transfer function to skip search page while going from one component to another?
- Peoplesoft Foundation tables
- tmunloadcf.exe - PSTUXCFG
- Application designer tips - Part1
- Java 观察者模式
- poj 1041 John's trip(欧拉回路入门题)
- tzc1200 求两直线的夹角
- jabber(转)
- tzc3056 点关于直线的对称点
- iframe 中方法的访问调用
- C# 索引器的简单例子
- Windows核心编程阅读笔记(1~7章)
- Yahoo 无插件网页媒体播放器
- Windows Phone开发(五)-- 导航控制