I have recently encountered a problem where my solution that used a vector of size n * n * m was giving TLE whereas when i changed the dimension to m * n * n it got accepted.(I kept the remaining logic and the rest of the code same).
Question 2057E1 - Another Exercise on Graphs (Easy Version)
TLE solution 301118680
ACCEPTED solution 301119202