If M2(i, j) = 1, then there is a path of length < = 2 (a path traversing at most 2 edges) from vertex i to vertex j in the graph G. Alternatively, if M2(i, j) = 0, then there is no such path. Now generalize from here...