def unique_ids_clustering(clustering, method):
    """
    Ensures that each paper is assigned only to one cluster by one of the methods:
     * 'first_occurence' - paper is assigned to the first cluster
     * 'unique_only' - only papers belonging to one cluster are taken into account
    """
    id_cluster = {}
    for i, cluster in enumerate(clustering):
        for pmid in cluster:
            if pmid not in id_cluster:
                id_cluster[pmid] = []
            id_cluster[pmid].append(i)
    if method == 'first_occurrence':
        return {str(k): v[0] for k, v in id_cluster.items()}
    elif method == 'unique_only':
        return {str(k): v[0] for k, v in id_cluster.items() if len(set(v)) == 1}