Using segments instead of nodes. Simple algorithm finished.