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

为什么会re啊?请高手指教?

Posted by tornado1986 at 2006-11-25 08:44:29 on Problem 1703
#include <stdio.h>
#include <stdlib.h>
#define MAX_VERTEX_NUM 100
struct ArcNode
{ 
    int adjver;
    struct  ArcNode   *nextArc;
};

struct   Vnode
{    int data;
    struct  ArcNode   *firstarc;
};

struct Graph
{
    struct Vnode AdjList[MAX_VERTEX_NUM];
    int vernum,arcnum;
};
struct Graph G;
int Visited[MAX_VERTEX_NUM],find;
void CreateGraph(int x,int y)
{
    int v1=x, v2=y,j;
    struct ArcNode *p;
        p=(struct ArcNode *)malloc(sizeof(struct ArcNode));
        p->adjver=y-1;
        j=x-1;
        p->nextArc=G.AdjList[j].firstarc;
        G.AdjList[j].firstarc=p;
        p=(struct ArcNode *)malloc(sizeof(struct ArcNode));
        p->adjver=x-1;
        j=y-1;
        p->nextArc=G.AdjList[j].firstarc;
        G.AdjList[j].firstarc=p;
}
void DFS(int x,int y,int k)
{
    struct ArcNode *temp;
    int w;
    Visited[x] = 1;
    if(y==x+1)
	{
		if(k==1)printf("In the same gang.\n");
	    if(k==-1)printf("In different gangs.\n");
		find=1;
		return;
    }
    for(temp = G.AdjList[x].firstarc; temp != NULL; temp = temp->nextArc)
    {
           w = temp->adjver;
           if(!Visited[w])
           {
              DFS(w,y,k*(-1));
           }
    }
}
int main()
{
	int k,m,i,x,y;
	char ch;
	scanf("%d",&k);
	while(k--)
	{
		scanf("%d %d",&G.vernum,&m);
		getchar();
		for(i=0;i<G.vernum;i++)
		{
			G.AdjList[i].data=i+1;
			G.AdjList[i].firstarc=NULL;
		}
		while(m--)
		{   
			
    		scanf("%c %d %d",&ch,&x,&y);
			getchar();
            switch(ch)
			{
			  case 'D':CreateGraph(x,y);break;
			  case 'A':find=0;
				       for(i=0;i<G.vernum;i++)Visited[i]=0;
				       DFS(x-1,y,1);
				       if(!find)printf("Not sure yet.\n");
					   break;
			}
		}
	}
	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