PROGRAM CCONNECT (INPUT,OUTPUT); TYPE DIM=ARRAY[ 1..10,1..10 ] OF INTEGER; VAR DATA:DIM; OLD:ARRAY[ 1..10 ] OF INTEGER; STACK:ARRAY[ 1..10 ] OF INTEGER; SEARCH:ARRAY[ 1..10,1..30 ] OF INTEGER; MATSU:DIM; MARK:ARRAY[ 1..10 ] OF INTEGER; ADJ_BUF:TEXT; M,KX,K,N,STOP,OTOP,V,W,P,I,J,KEY1,KEY2,KEY3,X,Y,Z:INTEGER; PROCEDURE CONNECT (VAR N,M:INTEGER; VAR MATSU:DIM); VAR X,Z:INTEGER; BEGIN M:=0; FOR X:=1 TO N DO MARK[ X ]:=0; Y:=1; REPEAT OTOP:=1; FOR X:=1 TO N DO OLD[ X ]:=0; V:=Y; STACK[ 1 ]:=Y; M:=M+1; FOR X:=1 TO OTOP DO MATSU[X,M]:=OLD[X]; FOR X:=1 TO OTOP DO FOR Z:=1 TO N DO IF Z=OLD[ X ] THEN MARK[ Z ]:=1; Y:=0; FOR X:=1 TO N DO IF MARK[ X ]=0 THEN Y:=X; UNTIL Y=0; END; PROCEDURE DEPTH(N:INTEGER); VAR I,J:INTEGER; BEGIN K:=K+1; FOR J:=1 TO N DO SEARCH[ J,K ]:=STACK[ J ]; OLD[OTOP]:=V; KEY1:=0; WHILE KEY1=0 DO BEGIN I:=1; KEY2:=0; WHILE KEY2=0 DO BEGIN W:=DATA[ V,I ]; P:=1; FOR J:=1 TO OTOP+1 DO IF W=OLD[J] THEN P:=0; IF P=1 THEN BEGIN STOP:=STOP+1; STACK[ STOP ]:=W; V:=W; OTOP:=OTOP+1; DEPTH(N); KEY2:=1; END ELSE BEGIN I:=I+1; IF I<=N THEN KEY2:=0 ELSE BEGIN KEY2:=1; STACK[ STOP ]:=0; KEY1:=1; KEY3:=0; WHILE (STACK[ 1 ]<>0) AND (KEY3=0) DO BEGIN K:=K+1; FOR J:=1 TO N DO SEARCH[J,K]:=STACK[ J ]; STOP:=STOP-1; IF STOP=0 THEN BEGIN KEY1:=1 END ELSE BEGIN V:=STACK[ STOP ]; KEY1:=0; KEY3:=1 END END END END END; END END; BEGIN READLN(N); RESET(ADJ_BUF); READLN(ADJ_BUF,DATA[I,J]); I:=0; WHILE (NOT EOF) AND (I