#P2746. Software Propagation in School Networks

    ID: 16009 Type: Default 1000ms 256MiB

Software Propagation in School Networks

Software Propagation in School Networks

In a network of schools, each school distributes software to some other schools according to a pre‐arranged protocol. Note that the distribution is directed: if school A sends the software to school B, it does not necessarily imply that school B sends it to school A.

Your tasks are divided into two subtasks:

  • Subtask A: Determine the minimum number of schools that must initially receive the software so that, following the distribution protocol, all schools eventually get the new software. In graph theoretic terms, if the schools and their distribution lists form a directed graph, the answer for this subtask equals the number of strongly connected components (SCCs) with zero in-degree in the condensation graph.
  • Subtask B: It is desired that, if the software is sent to any one school, it will eventually propagate to every school in the network. To achieve this, you are allowed to modify the distribution lists by adding new entries (each such modification adds one new recipient to a school's list). Determine the minimum number of modifications required to ensure that the network becomes strongly connected. In other words, if the condensation of the graph has more than one SCC, the answer is

    \(\max(|\{\text{SCCs with zero in-degree}\}|,\;|\{\text{SCCs with zero out-degree}\}|)\)

    and if the network is already strongly connected, no modification is needed.

The propagation follows the directed edges. Use the given protocols to compute the answers for both subtasks.

inputFormat

The first line contains two integers \(n\) and \(m\), where \(n\) is the number of schools and \(m\) is the number of directed edges representing the distribution relationships.

Each of the following \(m\) lines contains two integers \(u\) and \(v\) (1-indexed) indicating that school \(u\) sends the software to school \(v\).

outputFormat

Output two integers separated by a space. The first integer is the answer for Subtask A (the minimum number of initial schools that need to receive the software), and the second integer is the answer for Subtask B (the minimum number of modifications needed to make the network strongly connected).

sample

1 0
1 0