Cs50 Tideman Solution Instant
We assume pairs is already sorted (by sort_pairs ).
So the final correct version:
def compare_candidates(candidate1, candidate2, voter_preferences): """ Compare two candidates and determine which one is preferred by more voters. Cs50 Tideman Solution
: A pair is only locked if it does not create a cycle in the graph. For example, if A beats B and B beats C, you cannot lock a pair where C beats A, as this would create a loop where no clear winner exists. We assume pairs is already sorted (by sort_pairs )
if (locked[start][i] && is_path(i, end)) return true; end)) return true
void print_winner(void)