Editorial for COI '06 #2 Policija


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

A single depth-first search collects all the information needed to answer the queries. While searching, we store the following numbers for each vertex:

  • Discovery time – discrete time index at which we started processing the vertex
  • Finishing time – time index when we finished processing the vertex
  • Depth – the depth of the vertex in the DFS tree
  • lowlink – the vertex with the least discovery time, that is reachable from the current vertex or from its descendants (via a single back edge)

These numbers allow us to construct two useful functions:

  • \text{is_descendant}(A, B) – is vertex A in the subtree rooted at B
  • \text{find_related_child}(A, B) – when A is in vertex B's subtree, find the immediate child of B such that A is a descendant of that child (in other words, if B has multiple children, find which of those subtrees A is in)

With some case analysis, it is possible to answer the queries using the described functions.

For an in-depth discussion of depth-first search and its applications, see "Introduction to Algorithms" by Cormen et al. This problem is closely related to finding articulation points and bridges in a graph.


Comments

There are no comments at the moment.