Help in Codeforces 1487E

I simply implemented DFS on the complement graph formed by the 4 levels of nodes.
Can anyone tell me where the logic went wrong? I can’t seem to think of anything.

dp[v] stores the minimum possible cost if we traverse down the complement graph.

Please do point out anything which seems unclear in the code.

My submission