← 返回 bytedance 的题目列表Viral Campaign
类型:online_judge
On the TikTok platform, the goal is to identify the minimum number of users that must initially be given a trend such that the trend reaches every user. Influence spreads via the following relationships among users. Given n representing the total number of users, along with two arrays of equal size, influencers and followers, where influencers[i] is an influencer and followers[i] indicates the user who follows this influencer (if followers[i] is -1, it indicates this influencer has no followers). The task is to find the minimum number of users to whom the trend should initially be introduced to ensure it eventually reaches every user.\n\nExample:\n\nn = 4, influencers = [2, 1, 3, 4], followers = [1, 3, 2, -1]\n\nIntroducing the trend to users 4 and 1 will cover all users, requiring a minimum of 2 users.
Example
Input
4
2 1 3 4
1 3 2 -1