1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| # matrice adjacentre = determine les liens entre les stations
relation=[
[0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0],[1,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0],[0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0],
[0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0],
[0,0,0,1,1,0,0,1,0,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0],
[0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0],
[0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0],
[0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1],
[0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0]]
# print(relation[0][3])
# taille du réseau
taille=len(relation)
taille=int(taille)
print("Le réseau comporte",taille,"stations")
# saisie du sommet de départ
depart=input("Saisie du sommet de départ:")
depart=int(depart)
#saisie du sommet d'arrivée
arrivee=input("Saisie du sommet d'arriveé:")
arrivee=int(arrivee)
# mémorisation du parcours
parcours=[taille]
# initialisation des sommets à 0 car aucun sommet n'a été exploré
exploration=["non"]*taille
def explorer(position,profondeur):
# sauvegarde du chemin
parcours[profondeur]=position
# si la position correspond au sommet d'arrivée
if position==arrivee:
for i in range(0,taille):
print(parcours[i],end="")
# sinon la position ne correspond pas au sommet d'arrivee donc on marque le sommet comme exploré
exploration[position]="oui"
# on explore les autres chemins
for i in range(0,taille):
if(relation[position][i]==0 or exploration[i]=="non"):
explorer(i,profondeur+1)
# on marque la position comme non visitée
exploration[position]="non"
# lancement de l'exploration avec le départ et profondeur de 0
explorer(depart,0) |
Partager