| And how to do it in C++? Is there a function like 'seekeof'?WA#6 too((( Послано Rustam  8 сен 2008 22:32{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}program z1320;
 
 {$APPTYPE CONSOLE}
 
 uses
 SysUtils;
 type
 pnode = ^tnode;
 tnode = record
 b:longint;
 next:pnode;
 end;
 var a:array [1..1000] of pnode;
 c:array [1..1000] of longint;
 b:array [1..1000] of boolean;
 n,m,i,j,k,t:longint;
 x:pnode;
 procedure init;
 begin
 reset(input,'input.txt');
 rewrite(output,'output.txt');
 end;
 procedure print;
 begin
 close(input);
 close(Output);
 halt(0);
 end;
 procedure swap(var a,b:longint);
 var t:longint;
 begin
 t:=a;
 a:=b;
 b:=t;
 end;
 procedure dfs(k:longint);
 begin
 b[k]:=true;
 inc(c[m]);
 while a[k]<>nil do
 begin
 if b[a[k]^.b]=false then
 dfs(a[k]^.b);
 a[k]:= a[k]^.next;
 end;
 end;
 begin
 init;
 n:=0;
 while not seekeof(input) do
 begin
 read(i,j);
 new(x);
 x^.b:=j;
 x^.next:=a[i];
 a[i]:=x;
 new(x);
 x^.b:=i;
 x^.next:=a[j];
 a[j]:=x;
 if i<j then swap(i,j);
 if i>n then n:=i;
 end;
 m:=0;
 for i:=1 to n do
 if b[i]=false then
 begin
 inc(m);
 dfs(i);
 end;
 for i:=1 to m do
 if c[i]=2 then
 begin
 write(0);
 halt(0);
 end;
 write(1);
 print;
 end.
Re: WA#6 too((( type int=integer;
 var n,i,j,col:int;
 g:array[1..1000,1..1000] of byte;
 vid:array[1..1000] of boolean;
 v:array[1..1000] of int;
 
 procedure dsd(curr,p:int);
 var j:int;
 begin
 for j:=1 to n do
 if (g[curr,v[j]]=1) and (not vid[v[j]]) and (j<>p) then
 begin
 inc(col);
 vid[v[j]]:=true;
 dsd(v[j],curr);
 end;
 end;
 
 begin
 n:=0;
 while not EOF do
 begin
 readln(i,j);
 g[i,j]:=1;
 g[j,i]:=1;
 if not vid[i] then begin inc(n);v[n]:=i;vid[i]:=true;end;
 if not vid[j] then begin inc(n);v[n]:=j;vid[j]:=true;end;
 end;
 
 fillchar(vid,sizeof(vid),false);
 
 for i:=1 to n do
 if not vid[v[i]] then
 begin
 col:=0;
 vid[v[i]]:=true;
 dsd(v[i],0);
 if col<2 then begin write(0);halt;end;
 end;
 write(1);
 end.
 |