def get_node_cost(graph, node, cost_dict):
    """
        get cost of input node along
        If parent node cost is not calculated, return 0.
        This node calculate again in the loop by DAG structure.
    """
    cost = 0
    ancestors = graph.successors(node)
    if len(ancestors) == 0:
        return 1
    for ancestor in ancestors:
        try:
            cost += cost_dict[ancestor] / len(graph.predecessors(ancestor))
        except KeyError:
            return 0
    return cost
