How to approach this problem of shortest path with some extra conditions

Given a graph with M edges and N vertices with Source as Node 1 and destination as Node N. Each node has a color either black or white , and the edge has some weight associated with it.How to find the shortest path between source and destination with the condition that the difference between the black and white nodes is atmost 1.

I know how to solve this problem without the condition

Now,with the condition how to solve this problem.

PS:asked in hiring challenge

please explain the approach

U could use an approach similar to bellman ford

let dp[i][j] be the shortest path to i with difference between white and black nodes j

dp[i][j]=inf for all i,j

if 1 is black,dp[1][1]=0,if white dp[1][-1]=0

Repeat this step until dp[1][n] !=inf:

for all vertices v:

dp[v][j]=min(dp[v][j],dp[adj[v]][j+1]) if v is white,

and dp[v][j]=min(dp[v][j],dp[adj[v]][j-1]_ if v is black