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

这个1703的为什么会re啊?请高手指教?T_T

Posted by tornado1986 at 2006-11-26 10:39:40
我是用图的方法做的,但是提交却是runtime error T_T
#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)            //图的深度遍历,k是作关系判断,1为同一组,-1为不同一组。
{
    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;
		}                                      //初始化G。
		while(m--)
		{   
			
    		scanf("%c %d %d",&ch,&x,&y);
			getchar();
            switch(ch)
			{
			  case 'D':CreateGraph(x,y);break;    // D插入
			  case 'A':find=0;                    // A判断
				       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