Note that there is no need to check that no port appears twice. If that were the case, then the route couldn't include all the five ports.