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 1040. Airline Company

Help!!!Why I got WA???
Posted by Superthinker 23 Jul 2003 13:11
const
  MAX = 60;
  MAXL = 5000;
type
  Arr = array [1 .. MAX, 0 .. MAXL] of integer;

var
  Save : Arr;
  List : array [1 .. MAXL] of integer;
  Use : array [1 .. MAXL] of boolean;
  n, i, a, m : integer;

function GCD (ga, gb : integer) : integer;
  var
    gt : integer;
  begin
    while ga mod gb > 0 do
      begin
        gt := ga mod gb;
        ga := gb;
        gb := gt;
      end;
    Gcd := gb;
  end;

function Judge : boolean;
  var
    ji, jj, jt : integer;
    jb : boolean;
  begin
    ji := 1;
    jb := true;
    while (ji <= n) and jb do
      begin
        if Save [ji, 0] > 1
          then begin
                jt := List [Save [ji, 1]];
                for jj := 2 to Save [ji, 0] do
                  jt := GCD (jt, List [Save [ji, jj]]);
               end
          else jt := 1;
        jb := (jt = 1);
        ji := ji + 1;
      end;
    Judge := jb;
  end;

procedure Out;
  var
    oi : integer;
  begin
    writeln ('YES');
    for oi := 1 to m do
      write (List [oi], ' ');
    halt;
  end;

procedure Search (st : integer);
  var
    si : integer;
  begin
    for si := 1 to m do
      if Use [si]
        then begin
               Use [si] := false;
               List [st] := si;
               if st < m
                 then Search (st + 1)
                 else if Judge
                        then Out;
               Use [si] := true;
             end;
  end;

begin
  fillchar (Save, sizeof (Save), 0);
  readln (n, m);
  for i := 1 to n do
    Use [i] := true;
  for i := 1 to m do
    begin
      read (a);
      Save [a, 0] := Save [a, 0] + 1;
      Save [a, Save [a, 0]] := i;
      readln (a);
      Save [a, 0] := Save [a, 0] + 1;
      Save [a, Save [a, 0]] := i;
    end;
  Search (1);
  writeln ('NO');
end.
Stop posting your AC programs to the board! (-)
Posted by Dmitry 'Diman_YES' Kovalioff 24 Jul 2003 14:00
Re: Stop posting your AC programs to the board! (-)
Posted by Superthinker 24 Jul 2003 14:09
But my program is WA!!!
I've got AC.
Posted by Superthinker 27 Jul 2003 06:55