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

这题深度优先遍历不行吗,我运行时都会出现stack OVERFLOW

Posted by sunpy at 2008-07-30 12:51:52 on Problem 1258
下面是我的代码:
#include<stdio.h>

#define N 10
#define M 100000

int visited[N];
int a[N][N];
int min_len=0;

int depth_tranverse(int s,int n);

int main()
{
	int n;
	int i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			scanf("%d",*(a+i)+j);
	for(i=0;i<n;i++)
		visited[i]=0;
	depth_tranverse(0,n);
	return 0;
}

 int  depth_tranverse(int s,int n)
 {
	visited[s]=1;
	int i,min=M,min_node=n;
	for(i=0;i<n;i++)
		if(!visited[i]&&a[s][i]<min)
		{
			
				min=a[s][i];
				min_node=i;
		} 
	if(min_node!=n)	
	{
		min_len+=min;
		depth_tranverse(i,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