-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL1_C1.py
50 lines (49 loc) · 1.02 KB
/
L1_C1.py
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
'''
CICLU IN GRAF N FOLOSIND DF
graf neorientat (poate fi si neconex)
afisare ciclu
folosesc DF
'''
#de la a la b si de la b la a
n=7
m=8
la={1: [3],
2: [4],
3: [1, 4, 5, 6, 7],
4: [2, 3],
5: [3, 6],
6: [3, 5, 7],
7: [6, 3]
}
viz=[0]*(n+1)
parcurg=[]
tata=[0]*(n+1)
ok=0
def DF(x):
global ok
viz[x]=1
if ok==0:
for i in range (len(la[x])):
y=la[x][i]
if viz[y]==0:
tata[y]=x
parcurg.append(y)
DF(y)
if ok==1:
return
elif y != tata[x]:
print("ciclu elementar")
v=x
nr=1
while v!=y:
print(v, end=" ")
nr+=1
v=tata[v]
print(y, x, sep=" " )
#print("lungime ciclu: ", nr)
ok=1
start=1
DF(start)
print(parcurg)
if ok==0:
print("graf aciclic")