import pickle


def load_ddata(path, num):
    """
    Load data for defender.
    Input: 
        - path: path to pickled file
        - num: number of (source,target) pairs
    Return: graph, target nodes, community assignment, source nodes
    """
    with open(path, "rb") as f:
        data = pickle.load(f)
    graph = data["graph"]
    targets = {
        "random": data["targets_random"][:num],
        "degree": data["targets_degree"][:num],
        "community": data["targets_community"][:num],
    }
    sources = data["sources"][:num]
    node_com = data["node_com"]
    return graph, targets, sources, node_com