Algorithms and Data Structures for Programming Contests

Graph Traversal Algorithms (Cont'd)

Regroup (1)

High-level solution?

  1. Read input into a 2D array.
  2. Scan input to generate graph representation of connections:
    1. For each number, "flood-fill" to find all portal entrances and store in a list.
    2. For each portal exit, "flood-fill" to find all numbers and portal entrances and store in a list.
    Result is adjacency list representation of graph: list of neighbours for every node.
    Adjacency lists for sample input:
  3. Perform BFS/DFS on graph to generate lists of reachable points of interest — but modified so that points of interest cannot be used as intermediary nodes.
  4. Print sorted lists, in order.

What's "flood-fill"?

Try it! (2)

Regroup


© Copyright 2012–2015 François Pitt <francois.pitt@utoronto.ca>
last updated at 08:25 (EST) on Thu 5 Mar 2015
Creative Commons License Algorithms and Data Structures by François Pitt is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.