| ||||||||||
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 |
about graph#include "stdio.h" #define maxium 100 int s[maxium]; int first[maxium]; int last[maxium]; typedef struct graph{ int data[maxium][maxium]; int n; }graph; graph inputgraph(int x) { int i,j; graph g; g.n=x; for(i=1;i<=g.n;i++) { printf("输入第%d个节点",i); for(j=1;j<=g.n;j++) scanf("%d",&g.data[i][j]); } return g; } void change(graph g ) { int i,j,count=0; for(i=0;i<g.n;i++) first[i]=last[i]=0; for(i=1;i<=g.n;i++) { for(j=1;j<=g.n;j++) if(g.data[i][j]) { count++; if(count==1) { s[first[i]=(last[i-1]++)]=j; last[i]=first[i]; } else s[++last[i]]=j; } else last[i]=-1; count=0; } } int judge(int i) { if(i<0)i=-i; if(first[i]>last[i]) return 0; else {int j; for(j=first[i];j<=last[i];j++) {if(s[j]) {s[j]=-s[j]; judge(s[j]); } else return 1; } } } void main() { graph g; int n; printf("输入图的顶点数:"); scanf("%d",&n); g=inputgraph(n); change(g); if(judge(1)) printf("图中存在回路"); else printf("图中不存在回路"); } judge 有错误:stack overflow 应该怎么改正呢? 谢谢! Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator