class from descriptionFri, 20 Jan 2023

In many social networks, users have the option to specify other users as their friends. In addition, there is often a friend recommendation system that shows users people they know indirectly (through one of their friends) and suggests adding these people to the friends list. You have to develop a system for recommending friends. There are n users in the social network we are interested in, each of which is assigned a unique id from 1 to n. Each user of this network has no more than 5 friends. Obviously, no user is a friend to himself, and if user x is in user y's friends list, then user y is also in user x's friends list. Let's describe how the list of possible friends for each user should be formed. For user x, the list should include users y such that: y is not a friend of x and is not the same as x; user y and user x have at least one mutual friend; there is no such user y' who satisfies the first two constraints, and who has strictly more mutual friends with x than y has with x. In other words, the list of possible friends of user x includes all such users who are not his friends, for whom the number of mutual friends with x is maximum. Note that the list of possible friends may be empty. You have to write a program that generates lists of possible friends for all users of the network according to a given structure of the social network.

class FriendRecommender: def recommend(self, n, friends): """ :param n: the number of users in the network :type n: int :param friends: two-dimensional list of integers representing the structure of the network :type friends: list[list[int]] :return: list of possible friends for each user :rtype: list[set[int]] """

Questions about programming?Chat with your personal AI assistant