Official algorithmic problem description and constraints.
There are π cities located on a straight line. The cities are numbered from 1 to π.
Portals are used to move between cities. There are 4 colors of portals: blue, green, red, and yellow. Each city has portals of two different colors. You can move from city i to city π if they have portals of the same color (for example, you can move between a "blue-red" city and a "blue-green" city). This movement costs |πβπ| coins.
Your task is to answer π independent queries: calculate the minimum cost to move from city π₯ to city π¦.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.