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 1339. Babies

Why crash #12?
Posted by Maigo Akisame (maigoakisame@yahoo.com.cn) 26 Feb 2005 14:20
program ural1339;
const
  maxk=1000000;
var
  a,b:array[0..maxk]of longint;
  k,i,girl,t:longint;
begin
  read(k);
  for i:=1 to k do read(a[i]);
  for i:=1 to k do read(b[i]);
  for i:=1 to k do b[a[i]]:=-b[a[i]];

  for i:=1 to k do
    if b[i]>0 then begin
      girl:=i;
      repeat
        t:=a[b[girl]];
        a[b[girl]]:=girl;
        girl:=t;
        b[girl]:=-b[girl];
      until b[girl]=0;
    end;

  for i:=1 to k do
    b[a[i]]:=maxlongint;
  girl:=0;
  for i:=1 to k do begin
    if a[i]>0 then
      write(a[i])
    else begin
      repeat inc(girl);until b[girl]<maxlongint;
      write(girl);
    end;
    if i<k then write(' ') else writeln;
  end;
end.
try this one (+)
Posted by Neumann 3 Mar 2005 15:53
3
2 3 0
1 2 3

your pro get crash