def ground(visited_node_dict, end_node):
    """
        'grounds' a rod: it returns a list of nodes given a dict of nodes pointing to their precessor.

        For example:
        {2 : 1, 3 : 2, 5 : 3}, 5 -> [1, 2, 3, 5]
    """
    res = []
    curr = end_node
    while curr is not None:
        res.append(curr)
        curr = visited_node_dict.get(curr, None)
    return res[::-1]