|  | 
|  | 
| вернуться в форум | ..I am O(n^2) too and got AC.. I use a very simple algorithm..my code is very short..*just (for i:=1 to n do)check if the number appears in the A set of numbers after i.
 *set down the father of each number.
 *Just output.
 
 (i'm sorry that my English is really bad..)
 
 var
 con,temp,i,j:longint;
 fin:array[1..7500]of boolean;
 b,a,fa:array[1..7500]of integer;
 begin
 {$IFNDEF ONLINE_JUDGE}
 assign(input,'input.in');reset(input);
 assign(output,'output.out');rewritE(output);
 {$ENDIF}
 reaD(temp);
 con:=0;
 while temp<>0 do
 begin
 inc(con);
 a[con]:=temp;
 inc(b[temp]);
 read(temp);
 end;
 for i := 1 to con do
 for j := 1 to con+1 do
 if (not fin[j])and(b[j]=0) then
 begin
 fin[j]:=true;
 fa[j]:=a[i];
 deC(b[a[i]]);
 break;
 end;
 for i := 1 to con+1 do
 begin
 write(i,':');
 for j := 1 to con+1 do
 if (fa[j]=i)or(fa[i]=j) then
 write(' ',j);
 writeln;
 end;
 end.
 
 Edited by author 13.10.2009 15:09
 | 
 | 
|