POJ 1041 John's trip欧拉路
来源:互联网 发布:租赁备案 知乎 编辑:程序博客网 时间:2024/06/06 01:23
很简单的一道求欧拉路的题。用矩阵的话最好用关联矩阵,因为可能两点间连好几条路,用vector存的话记着要sort
#include<cstdio>#include<string.h>#include<stdlib.h>#include<stack>using namespace std; int map[46][2000],d[46],m;bool vis[2000];stack<int>st;int max(int a,int b){return a>b?a:b;}void euler(int u){int i;for(i=1;i<=m;i++)if(map[u][i] && !vis[i]){vis[i]=1;euler(map[u][i]);st.push(i);}}int main(){int x,y,z,i,j;while(scanf("%d %d",&x,&y) && !(x==0 && y==0)){m=0;memset(map,0,sizeof(map));memset(d,0,sizeof(d));memset(vis,0,sizeof(vis));scanf("%d",&z);d[x]++,d[y]++;map[x][z]=y,map[y][z]=x,m=max(m,z);int first=x>y?y:x;while(scanf("%d %d",&x,&y) && !(x==0 && y==0)){d[x]++,d[y]++;scanf("%d",&z);m=max(m,z);map[x][z]=y,map[y][z]=x;}for(i=1;i<=45;i++)if(d[i]%2)break;if(i<=45){printf("Round trip does not exist.\n");}else{euler(first);bool f=1;while(!st.empty()){if(f){printf("%d",st.top());f=0;}elseprintf(" %d",st.top());st.pop();}printf("\n");}}}
- 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
- 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 1185 炮兵阵地 状态压缩DP
- NS,DNS和A记录 之间关系
- Oauth2.0 文档地址
- tosting显示无限制小数位是0.0#
- POJ 1041 John's trip欧拉路
- HDU 4004 The Frog's Games
- Linux ARP协议源码解析
- 如何区分是手机访问网站,还是PC访问网站?
- OpenGL学习笔记(2)——动画制作
- arm裸机代码的学习
- 运算符
- 据说看完这21个故事的人,30岁前都成了亿万富翁。你是下一个吗?
- pthread参数传递