Eric is the most methodical employee at the Acme company. His manager assigned him a number of tasks for the quarter, and gave him a list of notes regarding the order they must be performed. Each note states that some task must be completed before some related task. If he goes to perform some task and sees that a rule exists requiring that this task be performed before an already completed task, then he cannot perform the task. Help Eric determine the maximum number of tasks he can complete.
Function Description
Complete the function tasks
in the editor. It must return an integer denoting the maximum number of tasks that Eric can complete.
tasks
has the following parameters(s):
int n
: integer, number of tasksa[a[0],...a[n-1]]
: an array of integers, the dependent tasksb[b[0],...b[n-1]]
: an array of integers, the primary tasksExample 1:
Input: n = 7, a = [1, 2, 3, 4, 6, 5], b = [7, 6, 4, 1, 2, 1]
Output: 6
Explanation:For example, Eric hasn=7
tasks to complete. His manager gives himm=6
notes on the order tasks must be performed. Here is a graph of the dependencies. The dependent array,a = [1, 2, 3, 4, 6, 5]
. His principal tasks array,b = [7, 6, 4, 1, 2, 1]
. Here is a graph of the dependencies: From the graph, it is easy to see that task 6 must be performed before task 2 and vice versa. He can only complete one of those two tasks before the other, so he must choose either task 6 or 2. He can complete7 - 1 = 6
tasks.
1 ≤ n ≤ 105
0 ≤ m ≤ n
- Each task depends on at most one other task.
input:
output: