Text this: A linear time algorithm for linearizing quadratic and higher-order shortest path problems