There may be much better ways of doing this, but here's what I would do.
First, I would treat p as being the parameter over the whole path (i.e. p=0 means that the point is at the beginning of the first line, and p=1 means that the point is at the end of the last line). Then I would work out...