I have the following graph nodes:

[![enter image description here](https://i.stack.imgur.com/0Tq0v.png)](https://i.stack.imgur.com/0Tq0v.png)

These nodes represent skills of a character in a video game. The 0th node is the base skill that all characters start with. The 1st node is a skill that requires the 0th node as a prerequisite. Likewise, the 2nd node requires the 1st node as a skill, which requires the 0th node as a skill. However, when a skill is learned, it does not need to be re-learned.

I am given an array T, which is `[0,0,1,1]` and an array A, which is `[2]`. The Kth skill can be learned only if the T[k]th skill has already been learned. 0 is root, so it is learned without needing any other skill. The above array is explained like this: `T[0] = 0`, `T[1]=0`, `T[2]=1`, `T[3]=1`, hence `T=[0,0,1,1]`. Array A tells me the skill(s) that I want to learn. My output needs to be the total number of skills I'd need to learn to learn skill 2. In the above example, the answer is `3`

Example 2
---------

[![enter image description here](https://i.stack.imgur.com/yDSzh.png)](https://i.stack.imgur.com/yDSzh.png)

In the 2nd graph, the answer is 5 because I am asked to learn 2,5,6 so I would be learning 0, 2, 3, 5, and 6. My inputs are these: `T=[0,0,0,0,2,3,3]` and `A = [2,5,6]`

I've been thinking about how to solve this. It's a coding exercise to improve my graph theory. But I don't know how to correlate between the T list and the A list algorithmically.

Example 3
---------

[![enter image description here](https://i.stack.imgur.com/AaAAQ.png)](https://i.stack.imgur.com/AaAAQ.png)

In the above example `T = [0,3,0,0,5,0,5]` and `A = [4,2,6,1,0]`.
I created `X = [0,1,2,3,4,5,6]` to map T to its connections.

What do I know?

* 0 is already always learned so `count = 1`
* Learning 4.

To learn 4, I have to learn 5, so that makes me learn 0 (which is learned). count = 1 + 2 = 3
* Learning 2.

To learn 2, I have to learn 0. count = 3 + 1 = 4
* Learning 6.

To learn 6, I have to learn 5 (already learned), which makes me learn 0 (already learned). count = 4 + 1 = 5
* Learning 1.

To learn 1, I have to learn 3, which makes me learn 0 (already learned).
count = 5 + 2 = 7

So I have to return this count, which is 7

My Code
-------

So far this is what I have:

```
def sol(T,A):
    count = 1
    x = [i for i in range(len(T))]

    if 0 in A:
       A.remove(0)

    for i in range(0, len(A)):
        indx = x.index(A[i])
        if T[indx]==0:
           count += 1
           break
        else:
           # nothing yet

```