@classmethod
def from_edges(cls, edges):
    """Form a Graph instance from the given {from: (to1, to2)} dict.

        The given 'edges' dictionary includes a key for each node from
        which a transition might originate. The corresponding value is
        either a node or a tuple of nodes; the graph includes an edge
        from the key node to each node in the value. For example, the
        dict {"A": "B", "B", ("C", "D")} defines 3 edges: A to B,
        B to C and B to D.
        """
    if edges is None:
        edges = {}
    states = set()
    distances = {}
    next = {}
    for k, v in edges.items():
        states.add(k)
        distances[k, k] = 0
        if not isinstance(v, (list, tuple)):
            v = v,
        for s in v:
            states.add(s)
            distances[k, s] = 1
            next[k, s] = s
    for k in states:
        for i in states:
            for j in states:
                segment1 = distances.get((i, k))
                if segment1 is None:
                    continue
                segment2 = distances.get((k, j))
                if segment2 is None:
                    continue
                candidate_distance = segment1 + segment2
                curpair = i, j
                current_distance = distances.get(curpair)
                if (current_distance is None or current_distance >
                    candidate_distance):
                    distances[curpair] = candidate_distance
                    next[curpair] = next.get((i, k), k)
    return cls(next)
