How do I invert this sparse lower triangular matrix I have square matrix of size $n$ filled with the following values
$$ T(i,j) = \begin{cases} 1 & i=j \\ -1 & j=k(i) \\ 0 & \mbox{otherwise} \end{cases} $$
where $k(i)=\{ \ldots \}$ is vector of integers, each one $k(i)<i$.
Example with $n=4$ generated from $k=\{ 0, 1, 1, 3 \}$
$$ T = \begin{bmatrix} 1 & 0 & 0 & 0 \\ -1 & 1 & 0 & 0 \\ -1 & 0 & 1 & 0 \\ 0 & 0 & -1 & 1 \end{bmatrix} $$
Notice that for each row $i$ there is only one $-1$ at the $k(i)$ column.
Now I want to find a rule for any $n>1$ that would generate $B=$T^{-1} = 
\begin{bmatrix} 
  1 &  &  &  \\ 
   & 1 &   & \mbox{all zeros}  \\
  & \ddots & 1 & \\
  \mbox{zeros}& \mbox{or ones}& & 1 
\end{bmatrix} $$
For the example $T$  above we have
$$ B=T^{-1} = 
\begin{bmatrix} 
1 & 0 & 0 & 0 \\ 
1 & 1 & 0 & 0 \\ 
1 & 0 & 1 & 0 \\ 
1 & 0 & 1 & 1 
\end{bmatrix} $$
Please try to include step by step example for the $T$ value above. 
Using matlab I initialize $T$ with the following code:
% Parent indices
k = [0,1,1,3]   % or [0,1,2,3], [0,1,1,1], [0,1,2,2], ...

% Construct adjacency matrix T
n = size(k,2);
T = eye(n);
for i=2:n
    T(i,k(i))=-1;
end

Edit 1
I tried the method of setting $(T^{-1})_{ij}=1$ if $j$ is a multiple of $k(i)$ and it didn't work. Here is the sample matlab code:
%Find B=inv(T)
B = eye(n);
for i=2:n
    for j=1:i-1
        for u=1:i-1
            if j==(k(i))^u
                B(i,j) = 1;
                break
            end
        end
    end
end

T=
     1     0     0     0
    -1     1     0     0
    -1     0     1     0
     0     0    -1     1

B=  
     1     0     0     0
     1     1     0     0
     1     0     1     0
     0     0     1     1
(not correct)

Edit 2
I tried the following matlab code
%Find B=inv(T)
B = eye(n);
for i=2:n
    for j=1:i-1
        B(i,j) = -T(i,k(i))*B(k(i),j);
    end
end

and it works it seems fine for cases where $k(i)<i$ (lower triangular matrix). With a little more testing I think I can award an answer. 
Edit 3
I have settled with
B=eye(n);
for i=2:n,
    j=k(i);
    while j>0,
        B(i,j)=1;
        j=k(j);
    end;
end

based on the answer & comments by user1551.  Here is the test code for posterity:
% Size
n  = 15
% k=Parent indices
k = zeros(1,n);
for i=2:n
    k(1,i) = int32(1+rand*(i-2) )
end
% Assemble T
T = eye(n);
for i=2:n
    T(i,k(i))=-1;
end

% Generate B=inv(T) with various methods

if(B*T==eye(n)) 
    disp('CORRECT')
else
    disp('FAIL')
end

 A: Let $T^{-1}=B$. Forward substitution gives $B_{i\ast}=e_i^T+B_{k(i)\ast}$. That is, the $i$-th row of $B$ is basically identical to the $k(i)$-th row, except that $b_{ii}$ is also equal to $1$. Put it another way,
$$
b_{ij}=\begin{cases}
1&\text{ if } j\in\left\{i,\,k(i),\,k^2(i),\ldots,\,k^{i-1}(i)\right\},\\
0&\text{ otherwise}.
\end{cases}
$$
A: Recall the general matrix multiplication formula:
$\left[\begin{array}{lcr}1&0&0\\a&1&0\\b&c&1\end{array}\right]
\left[\begin{array}{lcr}1&0&0\\\alpha&1&0\\\beta&\gamma&1\end{array}\right]
=\left[\begin{array}{lcr}1&0&0\\0&1&0\\0&0&1\end{array}\right]
$
requires
$\left\{\begin{array}{c}\alpha=-a,\\\beta=-b-\alpha c,\\ \gamma=-c\end{array}\right\}$
Similar recursive formulas hold for higher-dimensional arrays.  So to figure out your $\alpha,\beta,\gamma$, you need only to plug them into the formulas like this.  The fact that only one of each row will be -1, and the rest will be 0's allow for a simple formulation of your recursive formula:
$A^{-1}_{i,j}=-A_{i,k(i)}A^{-1}_{k(i),j}$
which you can start by filling out from the top.
For your example:
$T^{-1}_{21}=-T_{2,k(2)}T^{-1}_{k(1),1}=-T_{21}T^{-1}_{11}=--1\cdot 1=1$
$T^{-1}_{31}=-T_{31}T^{-1}_{11}=--1\cdot 1 = 1$
$T^{-1}_{32}=-T_{31}T^{-1}_{12}=--1\cdot 0 = 0$
$T^{-1}_{41}=-T_{43}T^{-1}_{31}=--1\cdot 1 = 1$
$T^{-1}_{42}=-T_{43}T^{-1}_{32}=--1\cdot 0 = 0$
$T^{-1}_{43}=-T_{43}T^{-1}_{33}=--1\cdot 1 = 1$
Note that at each step, you already know the value of $T^{-1}_{ij}$ by the time you need it (the first case being $T^{-1}_{11}=1$ because it's on the diagonal.
