Given a graph G, a vertex u, and an array VAL[] that associates every vertex v with a natural number(For each vertex v of V, VAL[v]=n, where n is a natural number).
A simple path in G is maximal if it can't be expanded anymore, maintaining the property to be simple.
Define an algorithm that verifies that all simple maximal paths, that depart from vertex u necessarily pass 2 vertices associated with numbers of different parity.
Is there an algorithm that can solve it in linear time on the dimensions of the graph?
Italian translation in this image:

edited: my first solution.
class color(Enum):
white = "white"
grey = "grey"
black = "black"
class Node(object):
def __init__(self, name, adjacency=[],
visited=False, predecessor=None):
self.name = name
self.adjacency = adjacency
self.visited = visited
self.predecessor = predecessor
def __repr__(self) -> str:
return f'''{self.name}'''
def append(self, vertex):
self.adjacency.append(vertex)
def dfs(start: Node, VAL: dict):
start.visited == color.grey
parity = VAL[start.name] % 2
for v in start.adjacenciesList:
if v.visited == color.white:
if parity != (VAL[v.name] % 2):
return True
if dfs(v):
return True
start.visited == color.black
return False
if __name__ == "__main__":
node1 = Node("A")
node2 = Node("B")
node3 = Node("C")
node4 = Node("D")
node1.append(node2)
node1.append(node3)
node2.append(node3)
node2.append(node4)
node3.append(node4)
VAL = {"A": 1, "B": 3, "C": 4, "D": 5}
print(dfs(node1, VAL))