!advance n_essai
!for i = 1 to $n
  Npi$i= $(npi$i)
!next
!!On vrifie que l'action sur S correspond  l'ajout d'un lment.
u=!itemcnt $Se
v=!itemcnt $S
x=1
sommet=0
!if $etp>1
!for i=1 to $v
  w=!item $i of $S
  !if $w isin $Se
  !else
    x=0
  !endif
!next i
!for i=1 to $u
  w=!item $i of $Se
  !if $w isin $S
  !else
    sommet=$w
  !endif
!next i
w=$[$v+1]
!if $u<>$w
  x=0
!endif
!endif

!!On vrifie que ce sommet i rend minimal pi(i).
y=1
w=0
!if $etp>1
u=$(pi$sommet)
!for i=2 to $n
  v=$(pi$i)
  !if $v notsametext inf
  !! w=1
    !if ($i notin $S) and ($v<$u)
      w=1
      y=0
    !endif
  !endif
!next i
!if $w=1 and $u issametext inf
  y=0
!endif
!else
!if $Se<>1
  y=0
!endif
!endif

!!On vrifie que la matrice ligne pi est bien mise  jour
z=1
!if $(pi$sommet) issametext inf
!for i=2 to $n
  !if $(Npi$i) notsametext $(pi$i)
    z=0
  !endif
!next i
!else
!if $etp>1
  !for i=2 to $n
    L=!line $sommet of $GM
    v=!item $i of $L
    !if $(pi$i) issametext inf
      u=$[$(pi$sommet)+$v]
    !else
      u=$[min($(pi$i),$(pi$sommet)+$v)]
    !endif
    !if $i isin $S
      w=0
    !else
      w=1
    !endif
    w=$[$v*$w]
!!  w<>0  <=>  il faut modifier
    !if ($w<>0) and ($(Npi$i)<>$u)
      z=0
    !endif
  !next i
!else
  !for i=2 to $n
    L=!line 1 of $GM
    u=!item $i of $L
    v=$(Npi$i)
    !if $u=0
      !if $v notsametext inf
        z=0
      !endif
    !else
      !if $v<>$u
        z=0
      !endif
    !endif
  !next i
!endif
!endif

!!Mise  jour des variables ou message d'erreur
!if ($x=0) or ($y=0) or ($z=0)
  !if $x=0
    error= $error modS
  !else
    !if $y=0
      error= $error modsom
    !else
      !if $z=0
        error=$error modpi
      !endif
    !endif
  !endif
!!si le sommet est faux, on remet les valeurs prcdentes. 
  Se=$S
  !for i=2 to $n
  !if $x=1 and $y=1 and $z=0
    nnpi$i=$(pi$i)
  !endif
    Npi$i=$(pi$i)
  !next i
!else
  u=!itemcnt $Se
  !advance etp
  S=$Se
  !for i=2 to $n
    pi$i=$(Npi$i)
  !next i
  pi=0
  !for i=2 to $n
    pi=$pi,$(pi$i)
  !next i
  !if $u=$n
    pi=0
    !for i=2 to $n
      u=$(pi$i)
      !if $u issametext inf
        pi=$pi,\infty
      !else
        pi=$pi,$u
      !endif
    !next i
    status=done
    !read calculrep
    module_score= $[min(10,max(ceil(10*max(10-2*($n_essai-$etp-1)/$etp,0))/10,0))]
  !endif
!endif
