solving the LEGO city train problem (no room for loops!)