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 |
求助 请各位帮我看看为什么总是Wrong Answer 呢#include<stdio.h> #define max 101 typedef struct Graph{ long ArrayGraph[max][max]; int Vnum; }Graph; typedef struct CTree{ int TVex[max],Tnum; int LVex[max],Lnum; }CTree; typedef struct MinVex{ int i; long Weight; }MinVex; Graph CurGraph; CTree CurTree; void InsertCTree(int Vnum); int FindMin(long *MinWeight); int main() { int i,j,Xnum,aa[max][max]; long MinWeight=0; scanf("%d",&CurGraph.Vnum); for(i=0;i<CurGraph.Vnum;i++) for(j=0;j<CurGraph.Vnum;j++) scanf("%ld",&CurGraph.ArrayGraph[i][j]); scanf("%d",&Xnum); for(i=0;i<Xnum;i++) { scanf("%d%d",&aa[i][0],&aa[i][1]); CurGraph.ArrayGraph[aa[i][0]-1][aa[i][1]-1]=0; /* CurGraph.ArrayGraph[aa[i][1]-1][aa[i][0]-1]=0;*/ } CurTree.Lnum=0; CurTree.Tnum=0; for(i=0;i<CurGraph.Vnum;i++){ CurTree.LVex[i]=i; CurTree.Lnum++; } InsertCTree(0); while(CurTree.Lnum!=0){ i=FindMin(&MinWeight); InsertCTree(i); } printf("%ld\n",MinWeight); return 1; } void InsertCTree(int Vnum) { int i,j; for(i=0;i<CurTree.Lnum;i++) if(CurTree.LVex[i]==Vnum) break; if(i>=CurTree.Lnum) return; for(j=i;j<CurTree.Lnum;j++) CurTree.LVex[j]=CurTree.LVex[j+1]; CurTree.Lnum--; CurTree.TVex[CurTree.Tnum]=Vnum; CurTree.Tnum++; return; } int FindMin(long *MinWeight) { MinVex CurMinVex; int i,j; CurMinVex.Weight=10001; for(i=0;i<CurTree.Tnum;i++) for(j=0;j<CurTree.Lnum;j++) if(CurGraph.ArrayGraph[CurTree.TVex[i]][CurTree.LVex[j]]<CurMinVex.Weight){ CurMinVex.i=CurTree.LVex[j]; CurMinVex.Weight=CurGraph.ArrayGraph[CurTree.TVex[i]][CurTree.LVex[j]]; } *MinWeight+=CurMinVex.Weight; return CurMinVex.i; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator