|
|
back to boardCheck this out Posted by asif 15 Jan 2002 11:39 I think my code is right. It's pretty straight forward. Can any one who solved this look at it? --------------------------code------------------------------------ int main(void) { int n,code[SIZE]; int *m[SIZE],c[SIZE]; int f[SIZE]; int i,j,k; n=h=0; while(scanf("%d",&code[n])==1) code[n++]--; for(i=0;i<=n;i++){ f[i]=c[i]=0; m[i]=(int *)malloc((1+f[i])*sizeof(int)); } for(k=0;k<n;k++) f[code[k]]++; for(i=0;i<=n;i++) if(f[i]==0) HeapInsert(i); for(k=0;k<n;k++){ i=code[k]; j=ExtractMin(); m[i][c[i]++]=j; m[j][c[j]++]=i; f[i]--; if(f[i]==0) HeapInsert(i); } for(i=0;i<=n;i++){ printf("%d:",i+1); qsort(m[i],c[i],sizeof(int),comp); for(j=0;j<c[i];j++) printf(" %d",m[i][j]+1); printf("\n"); } return 0; } |
|
|