Yet another shortest path problem
CodeChefOpen on judge ↗
You are given an undirected graph $G$ with $N$ nodes and $M$ edges. Each edge $e$ has a color $c_e$. Define the cost of a path as the number of times the edge color changes. Formally, if the path consists of edges $e_1, e_2, \cdots, e_k$ in this order, the cost of the path is the number of $1 \leq i < k$, such that $c_{e_i} \neq c_{e_{i+1}}$. You are given two nodes $s$ and $t$. Find the minimum
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start