Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这题深度优先遍历不行吗,我运行时都会出现stack OVERFLOW下面是我的代码: #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator