After reading a bunch of articles about graph theory, I think that the problem I am working on involves incidence matrices. There are three classes B, P and L. I know the relationship of every instance of class B with every instance of class P and so on for instances of Class L and P as well.
I mapped them in two matrices X and Y. My goal is to find out which instances of Class B are related to instances of Class L. I did a matrix multiplication of few examples of X and Y, and it seems to provide me with correct answer every time, but I want to theoretically understand why is this working. I tried looking up what does a product of two incidence matrices mean, but cannot find something which would explain this in layman's terms.
$$ X_{Class B \times Class P}= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 1 \\ \end{bmatrix} \qquad Y_{Class P \times Class L}= \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 1 \\ \end{bmatrix}. $$