Walks of Astronomical Length — Solution & Editorial
The adjacency matrix's K-th power counts walks: entry (1, N) of AK. Binary exponentiation of the matrix does it in O(N³ log K).
Complexity: O(N3 log K)
The adjacency matrix's K-th power counts walks: entry (1, N) of AK. Binary exponentiation of the matrix does it in O(N³ log K).
Complexity: O(N3 log K)