Why WA on test 7?
Послано
ss 12 авг 2005 20:28
Here is my code:
type My=record
den,ost,sez:longint;
end;
Matr=array[1..101,1..101] of longint;
var m,n,l,i,j,h,k,min,o,sum:longint;
a: Matr;
q: array[1..101] of longint;
w: array[1..101] of my;
f:boolean;
procedure floyd(var c:matr);
var i,j,k:longint;
begin
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if c[i,k]+c[k,j]<c[i,j] then c[i,j]:=c[i,k]+c[k,j];
for i:=1 to n do c[i,i]:=0;
end;
begin
readln(n,m);
for i:=1 to n do
for j:=1 to n do a[i,j]:= 1000000;
for i:=1 to m do begin
read(l);
for j:=1 to l do read(q[j]);
for j:=1 to l-1 do
for h:=j+1 to l do begin
a[q[j],q[h]]:=4;
a[q[h],q[j]]:=4;
end;
end;
floyd(a);
readln(k);
for i:=1 to k do readln(w[i].den,w[i].ost,w[i].sez);
min:=1000000;
for i:=1 to n do begin
sum:=0;
f:=true;
for j:=1 to k do begin
if w[j].sez=0 then
if (w[j].den<a[i,w[j].ost]) then begin
f:=false;
break;
end
else sum:=sum+a[i,w[j].ost];
end;
if (f) and (min>sum) then begin
o:=i;
min:=sum;
end;
end;
if min=1000000 then writeln(0)
else writeln(o,' ',min);
end.