simple implementation of SPFA on a small scale