We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In my opinion, the editorial's approach is unnecessarily complex. My approach is as follows:
WARNING: SPOILERS AHEAD!
Store edges in standard adjacency lists for each node, and sort them.
Set mid = 1, iterate from 1 to V.
Iterate through mid's edges (call these nodes b).
Iterate through b's edges (call these nodes a).
Count the number of ordered a-b pairs strictly (a < b < mid) (since the adjacency lists are sorted, you can terminate each loop according to this logic).
After all edges have been checked, run through the set of counts. For each count, add count * (count - 1) / 2 to the result.
Jogging Cats
You are viewing a single comment's thread. Return to all comments →
In my opinion, the editorial's approach is unnecessarily complex. My approach is as follows:
WARNING: SPOILERS AHEAD!