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 1085. Meeting

Why Wrong Answer on test#3
Posted by Филиппов Илья (УЛ) 22 Jan 2007 16:49
var
a:array[1..100,1..100] of integer;
b,c,r,money:array[1..100] of integer;
n,m,k,i,j,t,min,p,w:integer;
begin
readln(n,m);
fillchar(a,sizeof(a),$FF);
for i:=1 to m do
begin
read(t);
for j:=1 to t do
read(c[j]);
for j:=1 to t-1 do
for w:=j+1 to t do
a[c[j],c[w]]:=1;
end;
readln(k);
for j:=1 to k do
readln(money[j],b[j],r[j]);
for t:=1 to n do
for i:=1 to n do
for j:=1 to n do
if ((a[i,j]>a[i,t]+a[t,j])or(a[i,j]=-1))and(a[i,t]<>-1)and(a[t,j]<>-1)
then a[i,j]:=a[i,t]+a[t,j];
for i:=1 to n do
a[i,i]:=0;
min:=1000000;p:=0;
for i:=1 to n do
begin
t:=0;
for j:=1 to k do
if (money[j]<a[b[j],i]*4)or(a[b[j],i]=-1) then begin
t:=1000000;
break;
end
else if r[j]=0 then
t:=t+(a[b[j],i])*4;
if t<min then begin
min:=t;
p:=i;
end;
end;
if p=0 then writeln('0')
else writeln(p,' ',min);
end.