← 返回 amazon 的题目列表Product Recommendation System Using DFS
类型:online_judge
Design a system to track and recommend products based on friends' purchase records using a Depth-First Search (DFS) algorithm. Given a friend relationship graph and a list of purchase records, write code to output recommended products. Implement the following:
Input:
n: number of nodes (friends)
m: number of edges (friendship relations)
edges: an m x 2 array indicating friendship relations (a, b) indicates a and b are friends
purchases: an n x k array where each sub-array represents a user's purchase history
Output:
A set of recommended products for each user
Constraints:
Number of nodes n does not exceed 1000
Number of friendship relations m does not exceed 5000
Example
Input
3
2
0 1
1 2
2
apple banana
1
apple orange
1
banana kiwi