注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
第六题
TikTok Viral Campaign
TikTok is a widely - used social media platform where users follow influencers who shape their content preferences. Formally, if user A follows user B, then user A is said to be influenced by user B. Once a user is influenced by a trend, they immediately propagate this information to all users who follow them.
As a brand manager tasked with designing a viral campaign, your objective is to determine the minimum number of users who need to be initially targeted with the trend, such that the information eventually reaches every user on the platform. If a user is neither an influencer nor a follower, they are still a TikTok user and must be directly introduced to the viral campaign independently.
You are given an integer n, representing the total number of TikTok users, along with two lists - influencers and followers - each of size n. For each index i, influencers[i] represents an influencer and followers[i] represents the user who follows that influencer. (If followers[i] is - 1, it indicates that the corresponding influencer has no followers.)
It is important to note the following:
Some users may not have any followers. In such cases, followers[i] will be set to - 1, indicating that the corresponding influencer is not followed by anyone.
There may be mutual follow relationships, i.e., user a may follow user b, and user b may follow user a.
Some users might appear in the influo non - empty groups
Constraints
1 ≤ n ≤ 10^5
1 ≤ videoChunks[i] ≤ 10^9
1 ≤ k ≤ n
Input Format For Custom Testing
Sample Case 0
Sample Input For Custom Testing |STDIN|FUNCTION| |----|----| |7|videoChunks[] size n = 7| |8|videoChunks = [8, 9, 8, 2, 9, 9, 2]| |9| |8| |2| |9| |9| |2| |3|k = 3|
Sample Output 31
Explanation Given n = 7, videoChunks = [8, 9, 8, 2, 9, 9, 2], and k = 3. One of the optimal way is to partition the array into these three subarrays: [[8, 9, 8], [2, 9, 9], [2]].
Cost of first subarray = 8 + 8 = 16
Cost of second subarray = 2 + 9 = 11
Cost of third subarray = 2 + 2 = 4
Total cost = 16 + 11 + 4 = 31 It can be shown that the sum of the costs cannot be less than 31. Hence, the minimum total cost is 31.
只做出来第七题,第六题太难了,不会做,求大米看看其他面经 |