xc=!eval $xx_size*($click_x-$border)/$inssize+$x_size1
yc=!eval $yy_size*(-$click_y+$border)/$inssize+$x_size2

!if $status=waiting
  !if $opar<2
    pt=0
    !for i=1 to $n
      u=$(abscisse$i)
      v=$(ordonnee$i)
      d=$[(abs((($xc) - ($u))^2 + (($yc) - ($v))^2))^(1/2)]
      !if $d < $incert
        pt=$i
      !endif
    !next i
    !if $pt=0
      error=pas_de_point
    !else
      !if $etp=0
        ar=$pt
        ptabs=$(abscisse$pt)
        ptord=$(ordonnee$pt)
        etp=1
      !else
        ar=$ar,$pt
!!      L'arte a dj t dessine ?
        I=!item 1 of $ar
        J=$pt
        L=!line $I of $GCM
        u=!item $J of $L
        L=!line $J of $GCM
        v=!item $I of $L
!!      w=prsence d'une arte entre i et j ou de i vers j
        !if $gor=0
          !if ($u=1) or ($v=1)
            w=1
          !else
            w=0
          !endif
        !else
          w=$u
        !endif
        !if $opar1=0
          !if $w = 0
            GC=!exec pari M=[$GC]; M[$I,$J]=1; print(M)
            GCM=!translate internal ; to $\
$ in $GC
          !else
            error=arete_existe_deja
          !endif
        !else
          !if $w=1
            !if $gor=0
              GC=!exec pari M=[$GC]; M[$I,$J]=0; M[$J,$I]=0; print(M)
            !else
              GC=!exec pari M=[$GC]; M[$I,$J]=0; print(M)
            !endif
            GCM=!translate internal ; to $\
$ in $GC
          !else
            error=arete_n_existe_pas
          !endif
        !endif
        etp=0
      !endif
    !endif
!!  Prparation du trac des artes
    dessin_aretes=$empty
    !for i=1 to $n
      !for j=1 to $n
        L=!line $i of $GCM
        u=!item $j of $L
        !if $u=1
          param=$empty
          x1=$(abscisse$i)
          y1=$(ordonnee$i)
          x2=$(abscisse$j)
          y2=$(ordonnee$j)
          !if $gor=1
            x=$[$x1+$k*($x2-$x1)]
            y=$[$y1+$k*($y2-$y1)]
            param=arrow $x1, $y1, $x, $y, $kf, $color2
          !endif
          param=$param\
          line $x1, $y1, $x2, $y2, $color2
          dessin_aretes=$dessin_aretes\
          $param
        !endif
      !next j
    !next i
    !if $etp=1
      dessin_aretes=$dessin_aretes\
      disk $ptabs,$ptord, 6, $color3
    !endif
  !else
#   Le graphe construit est-il connexe ?
    !if $gor=0
      GC=!exec pari N=[$GC];\
      N=matrix($n,$n,i,j,max(N[i,j],N[j,i]));print(N)
    !endif
    D=!exec pari {n=$n; N=[$GC];\
    P=matrix(n,n,i,j,-1);\
    mod=0;\
    for(k=1,n,\
      P[k,k]=0;\
      mod=1;\
      while(mod,\
        mod=0;\
        for(i=1,n,\
          for(j=1,n,\
            if(N[i,j]*(P[k,i]+1),\
              if(P[k,j]+1,\
                if(P[k,j]>P[k,i]+1, P[k,j]=P[k,i]+1;mod=1),\
                P[k,j]=P[k,i]+1; mod=1)\
            );\
          )\
        )\
      )\
    );\
    print(P)}
    D=!trim $D
    DM=!translate internal ; to $\
$ in $D
    !if -1 isin $D
      v=0
    !else
      v=1
    !endif
  # Exemple de sommets non joints
    !if $v=0
      ar=$empty
      !for i=1 to $n
        !for j=1 to $n
          L=!line $i of $DM
          u=!item $j of $L
          !if $u=-1
            ar=$i, $j
          !endif
        !next j
      !next i
      u=!item 1 of $ar
      succ=!item 2 of $ar
      pb1=Le graphe n'est pas connexe : par exemple, il n'y a pas de chemin de $(N$u) vers $(N$succ).
    !endif
#   Y a-t-il suffisament d'artes ?
    nbar=0
    !for i=1 to $n
      !for j=1 to $n
        L=!line $i of $GCM
        u=!item $j of $L
        !if $u = 1
          !advance nbar
        !endif
      !next j
    !next i
    !if $nbar<$p
      v=0
      pb2=Votre graphe ne comporte pas suffisament d'artes. 
    !endif
    !if $v=1
      module_score=10
    !else
      module_score=0
      !if $pb1=$empty
        module_score=5
      !endif
      !if $pb2=$empty
        module_score=1
      !endif
    !endif
    status=done
  !endif
!endif

xc=0
yc=0
click_x=0
click_y=0
