A solution to the POJ 2502 Subway