So I’m doing this problem, and I coded a simple Dijkstra’s that WAs on most of the test cases. It’s methodology was the do a Dijkstra’s, treating an edge as 0 cost if it was unique and its cost otherwise.
I know why this is wrong- changing an edge and moving along it can affect the other node as well. So I planned to have a node state with the current location, the previous color, and whether I changed the previous color and then do a Dijkstra’s. However, I’m not sure if this would pass under the time limt.