Specification says that, The function should create the locked graph, adding all edges in decreasing order of victory strength so long as the edge would not create a cycle.
How are cycles created? Let's answer that first.
Cycles are created if there is at least one arrow pointed towards each candidate. Uhm, okay. It is easier said than done, right?
How do we suppose to generalize this rule in practice then? This is where things get a lil tricky.
For the sake of simplicity, let's try to illustrate a possible scenario:
- A wins over B
- B wins over C
- C wins over D
- D wins over A
You immediately spot the cycle there right? So by convention, if there is no cycle, we can say "once winner always winner!"
Now, all that being said, consider a function in which you are looping through all the pairs and trying to detect whether loser side of current pair was once a winner side of an earlier pair. Otherwise, locking them (
locked[winner][loser] = true).
I am assuming that you have already completed the sort_pairs function. So, you don't need to bother with decreasing order part as long as you start your loop from
pair_count since they are already sorted.