def inverted_dict(keys: list, key_val_dict: dict) -> dict:
    """
    Get val -> [keys] mapping for the given keys using key_val_dict
    :param keys: the keys we are interested in (a list)
    :param key_val_dict: the key -> val mapping
    :return: inverted dictionary of val -> [keys] (for the subset dict of given keys)
    """
    res = {}
    all_tuples = ((k, key_val_dict[k] if k in key_val_dict else 'no-parent-' + k) for k in keys)
    for k, v in all_tuples:
        if v in res:
            res[v].append(k)
        else:
            res[v] = [k]
    # making sure to remove duplicate keys
    res = dict((v, list(set(k_list))) for v, k_list in res.items())
    return res