Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

数组开小了……

Posted by 5D6D2 at 2012-09-21 22:37:37 on Problem 1041
贴代码纪念!
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator