
Problem statement is here.
My idea is let the adjacency matrix for the given graph be A and the second matrix in the input be B. The answer is YES if A^{2}==B otherwise NO.
But this solution gives TLE as the input is large and I used naive matrix multiplication. Should I use any faster matrix multiplication algorithm or other faster solution exists. Anyone help. Thanks in advance. 