I got WA, please help me! Give some test!
var N,M,i,j,k,gl,l:integer;
a:array[1..100,1..100]of integer;
z,s,c,b:array[1..100]of longint;
gmin,sum:longint;
suxx:boolean;
begin
{ assign(input,'1085.dat');reset(input);}
readln(N,M);
for i:=1 to N do for j:=1 to N do a[i,j]:=10000;
for i:=1 to N do a[i,i]:=0;
for i:=1 to M do
begin
read(K);
for j:=1 to K do read(z[j]);
for j:=1 to K do for l:=j+1 to K do begin a[z[j],z[l]]:=1;a[z[l],z
[j]]:=1;end;
end;
read(K);for i:=1 to K do read(s[i],c[i],b[i]);
for k:=1 to N do
for i:=1 to N do
for j:=1 to N do if a[i,k]+a[k,j]<a[i,j] then a[i,j]:=a[i,k]+a
[k,j];
gmin:=MaxInt;
for i:=1 to N do
begin
sum:=0;suxx:=false;
for j:=1 to N do if (b[j] = 0) then
begin
if a[c[j],i]*4>s[j] then
begin
suxx:=true;
break;
end;
sum:=sum+a[c[j],i]*4;
end;
if not suxx then
begin
if sum<gmin then begin gmin:=sum;gl:=i;end;
end;
end;
if gmin = maxint then writeln(0) else writeln(gl,' ',gmin);
end.