def dfs2(s, d, G, V):
    #step('V = ' + str(V))
    if noChildren(s, G): return False
    for n in children(s, G):
        if n in V: continue
        V.append(n)  
        if n == d: return True
        return dfs2(n, d, G, V)

def noChildren(s, G):
    return not s in G

def children(s, G):
    return G[s]

def hasPath(s, d, G):
    return dfs2(s, d, G, [s])

def step(msg):
    raw_input(msg)

G = {'A':['B'], 'B':['D', 'C'], 'D':['E'], 'C':['E']}

print hasPath('A', 'E', G)

G2 = {'A':['B'], 'B':['A', 'D', 'C'], 'D':['B', 'E'], 'C':['E']}

print hasPath('A', 'E', G2)

print hasPath('D', 'A', G2)

