Loading...
Loading...
Loading...
In a social app, a post is shared along one-way follow links: a link a to b means b sees what a shares. Starting with user s, count how many users end up seeing the post, including s.
Example
Input
5 4 0 1 1 2 3 2 2 0 0
Output
3
Users 0, 1 and 2 see it. User 3 follows 2 but nobody shares to 3.
Try the problem first. Open one hint at a time.
The links have a direction: only follow them from a to b.
Search from s and count the nodes you mark.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor