Handle trivial case of directly connected vertices correctly

In this case an empty path is returned and front() method of list would
present undefined behavior.

Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com>