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 |
Re:这题深度优先遍历不行吗,我运行时都会出现stack OVERFLOWIn Reply To:这题深度优先遍历不行吗,我运行时都会出现stack OVERFLOW Posted by:sunpy at 2008-07-30 12:51:52 > 下面是我的代码: > #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; > } > #include<stdio.h> #define N 100 #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); printf("%d",min_len); 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