Closed Walks on Octagon — Solution & Editorial
The (1,1) entry of the adjacency matrix's N-th power via fast exponentiation.
Complexity: O(V3 log N)
The (1,1) entry of the adjacency matrix's N-th power via fast exponentiation.
Complexity: O(V3 log N)