trying to solve Happy Valentine Day (Valentine Maze Game)

getting TLE

first i am mapping all my T, W and C to a map<pair, int>

then i am doing bfs to find all the minimum distances between all C, T and W

as C < 10 , T == 1, W == 1,

so a matrix[12][12] is crested and then jst back tracking the matrix from T to W via all C

i have also used dp with bitmask instead of backtrackingā¦ but still TLE

can anyone suggest me any way to optimize the solution

my backtrack solution link