So it is propably my mistake in my program... But I can't find it...
Here is my code :
[pascal]
TYPE
pelem = ^elem;
elem = record
dokad:longint;
next:pelem;
end;
{ a dynamic queue }
VAR
counter,y,sum1,sum2,pole,qw,q,x,a,b,n,m:longint;
tab1,tab2:array[1..5000] of pelem;
p:pelem;
koszt:array[1..5000] of longint;
used:array[1..5000] of boolean;
Procedure DFS(co:longint);
{ this procedure checks which jobs can't be done without doing our job }
VAR
p:pelem;
begin
used[co]:=true;
p:=tab1[co];
while p<>nil do
begin
if used[p^.dokad]=false then DFS(p^.dokad);
p:=p^.next;
end;
end;
Procedure DFS2(co:longint);
{ this one checks which jobs must be done before our job }
VAR
p:pelem;
begin
used[co]:=true;
p:=tab2[co];
while p<>nil do
begin
if used[p^.dokad]=false then DFS2(p^.dokad);
p:=p^.next;
end;
end;
Procedure dodaj1(zm1,zm2:longint);
{ adds a connection beetween zm1 and zm2 }
begin
New(p);
p^.dokad:=zm2;
p^.next:=tab1[zm1];
tab1[zm1]:=p;
end;
Procedure dodaj2(zm1,zm2:longint);
{ the same as above but to the other queue}
begin
New(p);
p^.dokad:=zm2;
p^.next:=tab2[zm1];
tab2[zm1]:=p;
end;
begin
counter:=0;
repeat
counter:=counter+1;
readln(n,m);
if (n<>0) or (m<>0) then
begin
for x:=1 to 500 do tab1[x]:=nil;
for x:=1 to 500 do tab2[x]:=nil;
for x:=1 to n do read(koszt[x]);
readln;
for x:=1 to m do
begin
readln(a,b);
dodaj1(a,b);
dodaj2(b,a);
end;
Writeln('Case #',counter,':');
readln(q);
for qw:=1 to q do
begin
read(pole);
for y:=1 to n do used[y]:=false;
sum1:=0; sum2:=0;
DFS2(pole);
for x:=1 to n do if used[x] then sum1:=sum1+koszt[x];
for y:=1 to n do used[y]:=false;
DFS(pole);
for x:=1 to n do if not used[x] then sum2:=sum2+koszt[x];
sum2:=sum2+koszt[pole];
Writeln(sum2-sum1);
end;
Writeln; readln; readln;
end;
until (n=0) and (m=0);
end.
[/pascal]
Do You have any idea what's wrong ??
Thanks in advance
![:D](./images/smilies/icon_biggrin.gif)