PROCEDURE BICOMPO(N : INTEGER ; VAR E : MAT ; VAR CLIST : LIST ; VAR CEDGE : EDGE); CONST NN=50; STACKMAX=100; TYPE STACK=ARRAY [0..STACKMAX] OF INTEGER; MAT =ARRAY [1..NN,1..NN] OF INTEGER; LIST =ARRAY [1..NN] OF INTEGER; EDGE =ARRAY [1..NN,1..2] OF INTEGER; VAR EE : MAT; SV : STACK; SE1 : STACK; SE2 : STACK; NUMBER : ARRAY[1..NN] OF INTEGER; BACK : ARRAY[1..NN] OF INTEGER; NUM : INTEGER; I,J,K,C,D,B : INTEGER; SW : BOOLEAN; FLAG : BOOLEAN; FUNCTION MIN (X,Y : INTEGER) : INTEGER; BEGIN IF X<=Y THEN MIN:=X ELSE MIN:=Y END; FUNCTION BOO (X,Y : INTEGER) : BOOLEAN; BEGIN IF NUMBER[X]>=NUMBER[Y] THEN BOO:=TRUE ELSE BOO:=FALSE END; FUNCTION TOP (XX : STACK) : INTEGER; BEGIN TOP:=XX[XX[0]] END; FUNCTION SEC (XX : STACK) : INTEGER; BEGIN SEC:=XX[XX[0]-1] END; PROCEDURE POP (VAR XX : STACK); BEGIN IF XX[0]=0 THEN WRITELN (lst,'No more stack area') ELSE XX[0]:=XX[0]-1 END; PROCEDURE PUSH (VAR XX : STACK; DATA : INTEGER); BEGIN IF XX[0]=STACKMAX THEN WRITELN (lst,'Stack Overflow') ELSE BEGIN XX[0]:=XX[0]+1; XX[XX[0]]:=DATA END END; FUNCTION EMPTY(XX : STACK) : BOOLEAN; BEGIN IF XX[0]=0 THEN EMPTY:=TRUE ELSE EMPTY:=FALSE END; FUNCTION NEXTEDGE(I : INTEGER; VAR J : INTEGER) :BOOLEAN; VAR FINED :BOOLEAN; BEGIN J := 0; REPEAT J := J + 1; FINED := ((E[I,J] = 1) AND (EE[I,J] = 0)) UNTIL FINED OR (J = N); IF FINED THEN BEGIN EE[I,J]:=1; EE[J,I]:=1 END; NEXTEDGE := FINED END; BEGIN SV[0]:=0; SE1[0]:=0; SE2[0]:=0; C:=0; D:=0; B:=1; FLAG:=TRUE; FOR I:=1 TO NN DO BEGIN CLIST[I]:=0; FOR J:=1 TO 2 DO CEDGE[I,J]:=0 END; FOR I:=1 TO N DO FOR J:=1 TO N DO EE[I,J]:=0; NUMBER[1]:=1; NUM:=2; PUSH(SV,1); FOR I:=2 TO N DO NUMBER[I]:=0; {FORWARD} WHILE FLAG DO BEGIN WHILE NEXTEDGE(TOP(SV),J) DO BEGIN PUSH(SE1,TOP(SV)); PUSH(SE2,J); IF NUMBER[J]>0 THEN BACK[TOP(SV)]:=MIN(BACK[TOP(SV)],NUMBER[J]) ELSE BEGIN NUMBER[J]:=NUM; NUM:=NUM+1; BACK[J]:=NUMBER[J]; PUSH(SV,J) END END; {BACKUP} IF SV[0] > 1 THEN BEGIN K:=SEC(SV); IF BACK[TOP(SV)]>=NUMBER[K] THEN BEGIN D:=D+1; CLIST[D]:=B; SW:=NOT (EMPTY(SE1)); WHILE SW DO IF BOO(NUMBER[TOP(SE1)],NUMBER[K]) AND BOO(NUMBER[TOP(SE2)],NUMBER[K]) THEN BEGIN C:=C+1; CEDGE[C,1]:=TOP(SE1); CEDGE[C,2]:=TOP(SE2); B:=C+1; POP(SE1); POP(SE2); SW:=NOT (EMPTY(SE1)) END ELSE SW:=FALSE; END ELSE BACK[K]:=MIN(BACK[K],BACK[TOP(SV)]); POP(SV) END ELSE BEGIN FLAG:=FALSE; CLIST[D+1]:=B END END END;