Fixed a huge bug in this solution

Turns out I needed fewer vertices than I originally thought. The graph that my comments described would not work, but because of an 'i' instead of a 'j', my code was working. Basically, a mistake was the only reason my old code worked, but I am pretty sure this solution is sound.