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

帮忙看看我的程序,找不到错误啊,为什么wa呢

Posted by LC19863014 at 2008-08-23 21:02:51 on Problem 1041
#include <iostream>
#include <algorithm>
using namespace std;
int path[2000];
int num;
struct Edge 
{
	int p1,p2;
	bool visited;
}edges[2000];
struct Vertex 
{
	int numOfEdges;
	int edges[50];
}vertexes[50];
void solve(int k,int edge)
{
	int i;
	for (i=0;i<vertexes[k].numOfEdges;i++)
	{
		if(!edges[vertexes[k].edges[i]].visited)
		{
			int nextJunction=edges[vertexes[k].edges[i]].p1;
			if(k==nextJunction)
				nextJunction=edges[vertexes[k].edges[i]].p2;
			edges[vertexes[k].edges[i]].visited=true;
			solve(nextJunction,vertexes[k].edges[i]);	
		}
	}
	path[num++]=edge;
}
int main()
{
	int x,y,z,startJunction,exist;
	int i;
	while (1)
	{
		scanf("%d%d",&x,&y);
		if(x==0 && y==0)
			break;
		memset(vertexes,0,sizeof(vertexes));
		memset(edges,0,sizeof(edges));
		scanf("%d",&z);
		edges[z].p1=x;
		edges[z].p2=y;
		edges[z].visited=false;
		vertexes[x].edges[vertexes[x].numOfEdges++]=z;
		vertexes[y].edges[vertexes[y].numOfEdges++]=z;
		startJunction=x;
		if(x>y)
			startJunction=y;
		while (1)
		{
			scanf("%d%d",&x,&y);
			if(x==0 && y==0)
				break;
			scanf("%d",&z);
			edges[z].p1=x;
			edges[z].p2=y;
			edges[z].visited=false;
			vertexes[x].edges[vertexes[x].numOfEdges++]=z;
			vertexes[y].edges[vertexes[y].numOfEdges++]=z;
		}
		for (i=1;i<=50;i++)
			sort(vertexes[i].edges,vertexes[i].edges+vertexes[i].numOfEdges);
		exist=1;
		for (i=1;i<=50;i++)
			if(vertexes[i].numOfEdges%2!=0)
			{
				exist=0;
				break;
			}
		if(exist==0)
		{
			printf("Round trip does not exist.\n");
			continue;
		}
		memset(path,-1,sizeof(path));
		num=0;
		solve(startJunction,0);
		for (i=num-2;i>=0;i--)
		{
			printf("%d ",path[i]);
		}	
		printf("\n");
	}
	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