Tap here to switch tabs
Problem
Submissions

Problem: Remove Methods From Project

Try to solve the Remove Methods From Project problem.

Statement

You are maintaining a codebase containing n methods labeled from 00 to n −1- 1.

You are given two integers n and k, and a 22D integer array invocations, where invocations[i] =[ai,bi]= [a_i, b_i] indicates that method aia_i invokes method bib_i.

A group of methods is identified as suspicious:

  • Method k is suspicious.

  • Any method directly or indirectly invoked by a suspicious method is also suspicious.

You want to remove all suspicious methods from the codebase. However, they can only be removed if no non suspicious method invokes any suspicious method. If at least one non suspicious method invokes a suspicious method, no methods can be removed.

Return a list containing the indices of all remaining methods. If the suspicious methods cannot be removed, return all n method indices. The list may be returned in any order.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq k ≤\leq n −1- 1

  • 0≤0 \leq invocations.length ≤2×105\leq 2 \times 10^5

  • invocations[i] =[ai,bi]= [a_i, b_i]

  • 0≤ai,bi≤0 \leq a_i, b_i \leq n −1- 1

  • ai≠bia_i \neq b_i

  • invocations[i] ≠\neq invocations[j]

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Remove Methods From Project

Try to solve the Remove Methods From Project problem.

Statement

You are maintaining a codebase containing n methods labeled from 00 to n −1- 1.

You are given two integers n and k, and a 22D integer array invocations, where invocations[i] =[ai,bi]= [a_i, b_i] indicates that method aia_i invokes method bib_i.

A group of methods is identified as suspicious:

  • Method k is suspicious.

  • Any method directly or indirectly invoked by a suspicious method is also suspicious.

You want to remove all suspicious methods from the codebase. However, they can only be removed if no non suspicious method invokes any suspicious method. If at least one non suspicious method invokes a suspicious method, no methods can be removed.

Return a list containing the indices of all remaining methods. If the suspicious methods cannot be removed, return all n method indices. The list may be returned in any order.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq k ≤\leq n −1- 1

  • 0≤0 \leq invocations.length ≤2×105\leq 2 \times 10^5

  • invocations[i] =[ai,bi]= [a_i, b_i]

  • 0≤ai,bi≤0 \leq a_i, b_i \leq n −1- 1

  • ai≠bia_i \neq b_i

  • invocations[i] ≠\neq invocations[j]