POJ 1041 John's trip
来源:互联网 发布:淘宝网一摩托车头盔 编辑:程序博客网 时间:2024/06/06 17:50
欧拉回路,基础题,但我做得那叫一个乱。。
这道题只要把边和顶点的概念颠倒着想就可以了
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <vector>using namespace std;const int maxN=2000;int maX,degree[maxN],st[maxN],top,map[maxN][maxN];bool vis[maxN];void dfs(int x){ for(int z=1;z<=maX;z++){ if(map[x][z]&&!vis[z]){ vis[z]=true; dfs(map[x][z]); st[++top]=z; } }}int main(){#ifndef ONLINE_JUDGE freopen("a.in","r",stdin); freopen("a.out","w",stdout);#endif int x,y; while(cin>>x>>y,x||y){ memset(map,0,sizeof(map)); memset(degree,0,sizeof(degree)); memset(vis,false,sizeof(vis)); int z; cin>>z; map[x][z]=y; map[y][z]=x; degree[x]++;degree[y]++; int start=min(x,y),maxV=max(x,y); maX=z; while(cin>>x>>y,x||y){ cin>>z; map[x][z]=y; map[y][z]=x; degree[x]++;degree[y]++; maX=max(maX,z); maxV=max(x,max(maxV,y)); start=min(x,min(start,y)); } bool solved=false; for(int i=1;i<=maxV;i++) if(degree[i]&1){ cout<<"Round trip does not exist."<<endl; solved=true; break; } if(solved) continue; top=0; dfs(start); for(int i=top;i>0;i--) printf("%d%c",st[i],i==1?'\n':' '); }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
- 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 C - John's trip
- Java IO流学习总结
- 关于bsp的一些东西
- Android ApiDemos示例解析(9):App->Activity->Persistent State
- [linux]int main(int argc,char* argv[])详解
- Iterator 接口的使用 所有的Collection接口类都有一个iterator方法 ,Iterator对象的删除
- POJ 1041 John's trip
- java操作excel之读取excel的内容
- 利用GoogleApi根据经纬度查询地名,和根据地名查询经纬度Java代码
- 圣殿骑士WPF企业内训资源下载
- Android 启动过程详解
- ORA-28000: the account is locked-的解决办法
- java变量指定目录下所以的文件和文件夹
- 一步一步学习hadoop(三)
- Linux系统启动引导流程