You're working as a software engineer maintaining a large codebase with n methods numbered from 0 to n-1. Your team has discovered a critical bug in method k! ๐
The problem is that this buggy method might have infected other methods through method invocations. When method a calls method b, any bug in a could potentially affect b.
You're given:
n: Total number of methodsk: The method with the known buginvocations[][]: Whereinvocations[i] = [a, b]means methodainvokes methodb
Your mission: Remove all suspicious methods (the buggy method k and any methods it calls directly or indirectly). However, there's a catch! You can only remove a group of methods if no external method calls into that group. If it's impossible to safely remove all suspicious methods, don't remove any.
Return an array of all remaining method numbers after the removal, in any order.
Input & Output
Constraints
- 1 โค n โค 105
- 0 โค k โค n - 1
- 0 โค invocations.length โค 2 ร 105
- invocations[i].length == 2
- 0 โค ai, bi โค n - 1
- ai โ bi
- No duplicate invocations