def connected_pair(dmrs, first_id, second_id):
    """
    Check if a pair of nodes are connected to each other
    """
    cover = set()
    queue = {first_id}
    while queue:
        new = queue.pop()
        cover.add(new)
        for adjacent in dmrs.get_neighbours(new, nodeids=True, itr=True):
            if adjacent == second_id:
                return True
            elif adjacent not in cover:
                queue.add(adjacent)
    return False
