Step 1: President = citizen # 0… Build adjacency list by scanning all pairs of citizens … O(n^2)
Step 2: Using adjacency create a graph matrix with connections represented by 1 and disconnections by INFINITY
Step 3: Using BreadthFirstSearch from each vertex (citizen#) traverse graph till you reach president. Maintain a count as to how many of your BFS reached the President.
This should be less that O(n^3). @vgamma@adityakhanna1999