Replies: 3 comments 1 reply
-
Vis[0] = nodo non visitato |
Beta Was this translation helpful? Give feedback.
0 replies
-
l'idea è quella di controllare se esiste un cammino da y a x def esiste_cammino(G, y, z){
vis = [0....0]
vis[z] = 1
stack.push(z)
while stack is not empty{
if vis[v.adiacenti[0]] == 0{
w = v.adiacenti[0]
if w == y{
return true
}
stack.push(w)
}
elif v.adiacenti == []{
stack.pop()
}
else{
v.adiacenti.remove[0]
}
}
return false
}
def main(G, x, y, z){
if esiste_cammino(G, y, z) == true && esiste_cammino(G, x, y) == true{
return 'YES'
}
else{
return false
}
}
// costo = O(n+m) Dimostrazione correttezza: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Che qualità ragazzi
Beta Was this translation helpful? Give feedback.
All reactions