ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1069. Prufer Code

[Help] Crash #4 ( Access Violation )
Posted by Nguyen Khac Tung 3 Mar 2011 19:04
- Do you know test 4 ?
- Any helpful tests ?
- If not, please pick bugs from my code. My algo: Find minimal, adjacent list, output sorted list. Tks a loooottttttt

Program Prufer_Code;
Type
        pnode = ^node;
        node = Record
         data:Longint;
         next:pnode;
End;

Var     adjList:Array[0..7500] of pnode;
        temp:pnode;
        A,C,minS:Array[0..7500] of Longint;
        n,i,j,s,p,q,m:Longint;
        fi:Text;
Procedure add(k:Longint;var x:pnode);
Var
        y,z:pnode;
Begin
        If (x=nil) then
         Begin
          new(x);
          x^.data:=k;
         End
        Else
         Begin
          new(y);
          y^.data:=k;
          y^.next:=x;
          x:=y;
         End;
End;

Begin

                n:=0;
                While not seekeof do
                 Begin
                  inc(n);
                  Read(A[n]);
                 End;

                For i:=1 to n+1 do
                 Begin
                  inc(C[i]);
                  inc(C[A[i]]);
                 End;
                dec(C[A[n+1]],2);
                p:=0;

                For i:=1 to n+1 do
                 If C[i]=1 then
                  Begin
                   inc(p);
                   minS[p]:=i;
                  End;

                For i:=1 to n do
                 Begin
                  q:=minS[1]; m:=1;
                  For j:=2 to p do
                   If minS[j]<q then
                    Begin
                     q:=minS[j];
                     m:=j;
                    End;
                  j:=q; minS[m]:=99999;


                  add(j,adjList[A[i]]);
                  add(A[i],adjList[j]);
                  dec(C[A[i]]);

                  If C[A[i]]=1 then
                   Begin
                    inc(p);
                    minS[p]:=A[i];
                   End;

                 End;

                For i:=1 to n+1 do
                 Begin
                  FillChar(C,sizeof(C),0);
                  temp:=adjList[i];
                  p:=0;
                  while temp<>nil do
                   Begin
                    inc(C[temp^.data]);
                    temp:=temp^.next;
                   End;
                  Write(i,': ');
                  For j:=1 to 7500 do
                   If C[j]=1 then Write(j,' ');
                  Writeln;
                 End;
End.
Re: [Help] Crash #4 ( Access Violation )
Posted by Tayamarn 9 Jun 2011 12:24
I receive Access violation it test 4 too. :(
Do anyone know the test?
test 4
Posted by BaJIuK 4 Nov 2011 22:30
I was crashed on this test, because i forget to fill inf in cells of heap, before i start to solve. Also you can try this test:
input: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output: is obvious
Re: [Help] Crash #4 ( Access Violation )
Posted by lingdian618 30 Mar 2014 08:52
Are you store the double edge but didn't double the edge memory?