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

Maigo Akisame (maigoakisame@yahoo.com.cn) Why WA on test #2? [5] // Problem 1085. Meeting 5 Jul 2004 14:49
program ural1085;
const
  max=100;
  price=4;
  inf=65535;
var
  cost:array[1..max,1..max]of word;
  money:array[1..max]of word;
  stop:array[1..max]of byte;
  mt:array[1..max]of boolean;
  n,m,l,k,ans,i,j:byte;
  min,total:longint;
  ok:boolean;
begin
  {Make graph}
  fillchar(cost,sizeof(cost),255);
  readln(n,m);
  for i:=1 to m do begin
    read(l);
    for j:=1 to l do
      read(stop[j]);
    for j:=1 to l-1 do
      for k:=j+1 to l do begin
        cost[stop[j],stop[k]]:=price;
        cost[stop[k],stop[j]]:=price;
      end;
  end;
  for i:=1 to n do
    cost[i,i]:=0;

  {Floyd}
  for k:=1 to n do
    for i:=1 to n do
      for j:=1 to n do
        if (cost[i,k]<inf) and (cost[k,j]<inf) then
          if cost[i,k]+cost[k,j]<cost[i,j] then
            cost[i,j]:=cost[i,k]+cost[k,j];

  {Friends info}
  readln(k);
  for i:=1 to k do begin
    readln(money[i],stop[i],j);
    mt[i]:=j=1;
  end;

  {Main}
  ans:=0;min:=maxlongint;
  for i:=1 to n do begin
    total:=0;ok:=true;
    for j:=1 to k do
      if (cost[stop[j],i]=inf) or not mt[j] and (cost[stop[j],i]>money[j]) then begin
        ok:=false;
        break;
      end
      else
        inc(total,cost[stop[j],i]);
    if ok then
      if total<min then begin
        ans:=i;
        min:=total;
      end;
  end;

  {Output}
  if ans=0 then
    writeln(0)
  else
    writeln(ans,' ',min);
end.
Slava Medvedev(PetrSU) Re: Why WA on test #2? // Problem 1085. Meeting 27 Jul 2004 16:05
Maigo Akisame (maigoakisame@yahoo.com.cn) wrote 5 July 2004 14:49
program ural1085;
const
  max=100;
  price=4;
  inf=65535;
var
  cost:array[1..max,1..max]of word;
  money:array[1..max]of word;
  stop:array[1..max]of byte;
  mt:array[1..max]of boolean;
  n,m,l,k,ans,i,j:byte;
  min,total:longint;
  ok:boolean;
begin
  {Make graph}
  fillchar(cost,sizeof(cost),255);
  readln(n,m);
  for i:=1 to m do begin
    read(l);
    for j:=1 to l do
      read(stop[j]);
    for j:=1 to l-1 do
      for k:=j+1 to l do begin
        cost[stop[j],stop[k]]:=price;
        cost[stop[k],stop[j]]:=price;
      end;
  end;
  for i:=1 to n do
    cost[i,i]:=0;

  {Floyd}
  for k:=1 to n do
    for i:=1 to n do
      for j:=1 to n do
        if (cost[i,k]<inf) and (cost[k,j]<inf) then
          if cost[i,k]+cost[k,j]<cost[i,j] then
            cost[i,j]:=cost[i,k]+cost[k,j];

  {Friends info}
  readln(k);
  for i:=1 to k do begin
    readln(money[i],stop[i],j);
    mt[i]:=j=1;
  end;

  {Main}
  ans:=0;min:=maxlongint;
  for i:=1 to n do begin
    total:=0;ok:=true;
    for j:=1 to k do
      if (cost[stop[j],i]=inf) or not mt[j] and (cost[stop[j],i]>money[j]) then begin
        ok:=false;
        break;
      end
      else
        inc(total,cost[stop[j],i]);
    if ok then
      if total<min then begin
        ans:=i;
        min:=total;
      end;
  end;

  {Output}
  if ans=0 then
    writeln(0)
  else
    writeln(ans,' ',min);
end.


Sorry, See below

Edited by author 27.07.2004 16:09
Slava Medvedev(PetrSU) Re: Why WA on test #2? [3] // Problem 1085. Meeting 27 Jul 2004 16:07
A
Maigo Akisame (maigoakisame@yahoo.com.cn) wrote 5 July 2004 14:49
program ural1085;
const
  max=100;
  price=4;
  inf=65535;
var
  cost:array[1..max,1..max]of word;
  money:array[1..max]of word;
  stop:array[1..max]of byte;
  mt:array[1..max]of boolean;
  n,m,l,k,ans,i,j:byte;
  min,total:longint;
  ok:boolean;
begin
  {Make graph}
  fillchar(cost,sizeof(cost),255);
  readln(n,m);
  for i:=1 to m do begin
    read(l);
    for j:=1 to l do
      read(stop[j]);
    for j:=1 to l-1 do
      for k:=j+1 to l do begin
        cost[stop[j],stop[k]]:=price;
        cost[stop[k],stop[j]]:=price;
      end;
  end;
  for i:=1 to n do
    cost[i,i]:=0;

  {Floyd}
  for k:=1 to n do
    for i:=1 to n do
      for j:=1 to n do
        if (cost[i,k]<inf) and (cost[k,j]<inf) then
          if cost[i,k]+cost[k,j]<cost[i,j] then
            cost[i,j]:=cost[i,k]+cost[k,j];

  {Friends info}
  readln(k);
  for i:=1 to k do begin
    readln(money[i],stop[i],j);
    mt[i]:=j=1;
  end;

  {Main}
  ans:=0;min:=maxlongint;
  for i:=1 to n do begin
    total:=0;ok:=true;
    for j:=1 to k do
      if (cost[stop[j],i]=inf) or not mt[j] and (cost[stop[j],i]>money[j]) then begin
        ok:=false;
        break;
      end
      else
        if mt[j] then   {!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
          inc(total,cost[stop[j],i]);
    if ok then
      if total<min then begin
        ans:=i;
        min:=total;
      end;
  end;

  {Output}
  if ans=0 then
    writeln(0)
  else
    writeln(ans,' ',min);
end.
Maigo Akisame (maigoakisame@yahoo.com.cn) What do u mean? [1] // Problem 1085. Meeting 27 Jul 2004 17:17
Saturn (HUS) Re: What do u mean? // Problem 1085. Meeting 28 Jul 2004 13:28
It's mean you did't read the solution above carefully
Did you see this (!!!!!!!!!!!!!!!!) in the solution?
Maigo Akisame (maigoakisame@yahoo.com.cn) Thanx. But you omitted a 'not'. // Problem 1085. Meeting 29 Jul 2004 17:06