| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
数组开小了……贴代码纪念!
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
const int NMax=2000,MMax=50;
int N,M,G[NMax][MMax],D[MMax],S[NMax],top;
bool visit[NMax];
void DFS(int a) {
for(int i=1;i<=M;i++) if(G[i][a]&&(!visit[i])) {
visit[i]=1;
DFS(G[i][a]);
S[top++]=i;
}
}
int main()
{
int x,y,z,start;
while(scanf("%d%d",&x,&y),x) {
top=0;
N=M=-1;
start=min(x,y);
memset(G,0,sizeof(G));
memset(D,0,sizeof(D));
memset(visit,0,sizeof(visit));
scanf("%d",&z);
N=max(N,max(x,y));
M=max(M,z);
G[z][x]=y;
G[z][y]=x;
D[x]++;D[y]++;
while(scanf("%d%d",&x,&y),x) {
scanf("%d",&z);
G[z][x]=y;
G[z][y]=x;
D[x]++;D[y]++;
N=max(N,max(x,y));
M=max(M,z);
}
bool flag=1;
for(int i=1;i<=N;i++) if(D[i]%2!=0){
flag=0;
break;
}
if(!flag) puts("Round trip does not exist.");
else {
DFS(start);
for(int i=top-1;i>=1;i--) printf("%d ",S[i]);
printf("%d\n",S[0]);
}
}
getchar();getchar();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator