color=brown
M1=!exec pari print(matrix($NN,$N,i,j,random(2)))
M=!translate internal ; to $\
$ in $M1
m=$[$N+1]
mm=$[$NN+1]
!! n est le nombre de sommets
xsize=$[$m+2]
ysize=$[$mm+1]
dessin=xrange -0.5,$xsize\
yrange -0.5,$ysize\
linewidth 4\
parallel 1,1,$m+1,1,0,1,$mm,$color\
line 1,1,1,$mm,$color\
line 1+$m,1,1+$m,$mm,$color

MM=
graphe=
U1=
U=1
U2=
!for j=1 to $mm
	dessin=$dessin\
	disk 1,$j,8,blue\
	disk $m+1,$j,8,blue
	graphe=$graphe\
1,$j
	s=!line $j of $M
	!for i=1 to $N
		u=!item $i of $s
		!if $u=1
			U=!append item $[$i+1] to $U
			dessin=$dessin\
			line $i+1,$j,$i+1,$[$j+1],$color\
disk $i+1,$j, 8,blue\
disk $i+1,$[$j+1],8,blue
			!if  $[$i+1] notitemof $U1 
				graphe=$graphe\
				$[$i+1],$j
			!endif
			graphe=$graphe\
$[$i+1],$[$j+1]
		!endif
	!next i
	U=!append item $[$m+1]  to $U
graphe=$graphe\
$[$m+1],$j
	U2=!listuniq $U1,$U
	U2=!sort item $U2
	MM=!append line $U2 to $MM
	U1=$U
	U=1
	U2=
!next j
graphe=!nonempty lines $graphe
n=!linecnt $graphe

!!calcul de la matrice du graphe
G=!exec pari G=matrix($n,$n); print(G);
!for i=1 to $n
	L=!line $i of $graphe
	L1=!item 2 of $L
	L2=!item 1 of $L
	dessin = $dessin\
text $color, $[$L2+0.2],$[$L1+0.2],medium,$(N$i)
		!for j=$[$i+1] to $n
			LL=!line $j of $graphe
			LL1=!item 2 of $LL
			LL2=!item 1 of $LL
			!if $LL1=$L1 
				S=!line $L1 of $MM
				S=!sort item $S
				S=!nonempty item $S
				c1=$[min($L2,$LL2)]
				c2=$[max($L2,$LL2)]
				t1=!positionof item $c1 in $S
				t2=!positionof item $c2 in $S
				!if $[$t1+1]=$t2 or $[$t1-1]=$t2
					G=!exec pari M=Mat([$M1]);G=Mat([$G]);G[$i,$j]=1;print(G);
				!endif
			!endif

			!if ($LL1=$[$L1+1] or $LL1=$[$L1-1]) and $LL2=$L2
				G=!exec pari G=Mat([$G]); G[$i,$j]=1; print(G);
			!endif
			G=!nonempty lines $G
	!next j
!next i

G=!exec pari n=$n; G=Mat([$G]); print(G+G~);
G=!trim $G

GM=!translate internal ; to $\
$ in $G
etp=0
GC=!exec pari M=matrix($n,$n,i,j,0);print(M)
D=$G
GCM=!translate internal ; to $\
$ in $GC
DM=!translate internal ; to $\
$ in $D
