graph = {}
def dfs(graph, node, visited):
if node not in visited:
visited.append(node)
for n in graph[node]:
dfs(graph,n, visited)
return visited
n = int(input())
drinks = [d for d in input().split()]
m = int(input())
obs = []
for _ in range(m):
di, dj = input().split()
obs += [(di, dj)]
for drink in drinks:
graph[drink] = []
for drink1, drink2 in obs:
graph[drink1].append(drink2)
order = dfs(graph,drinks[0], [])
print(order)
Hi guys!
I'm supposed to input a certain amount of drinks and their names. After that I would have to input the number of combinations and the combinations which pratically serve as the vertices for the graph
Sample input would be:
7
A B C D E F G
12
A B
A C
A D
B D
B E
C F
D C
D F
E D
G D
G E
G F
The problem is my output is ['A', 'B', 'D', 'C', 'F', 'E']. It's missing 'G' and is not one of the three possible outputs ['A','B','G','E','D','C','F'], ['A','G','B','E','D','C','F'], or ['G','A','B','E' ,'D','C','F']. I have no clue why

