#K69332. Minimum Traffic Lights

    ID: 33063 Type: Default 1000ms 256MiB

Minimum Traffic Lights

Minimum Traffic Lights

You are given a grid of size \(n \times m\) along with a list of \(k\) important intersections. A traffic light placed on an avenue (row) or a street (column) will cover every intersection on that row or column. The goal is to install the minimum number of traffic lights such that every important intersection is covered by at least one traffic light located on the same row or column.

In mathematical terms, if \(R\) represents the set of unique row indices and \(C\) represents the set of unique column indices for the intersections, then the answer is:

[ \min(|R|,|C|) ]

Find this minimum number of traffic lights.

inputFormat

The input is given via stdin and has the following format:

  1. The first line contains three space-separated integers \(n\), \(m\), and \(k\) representing the number of rows, columns, and important intersections respectively.
  2. Each of the next \(k\) lines contains two space-separated integers \(a_i\) and \(b_i\), indicating the row and column of an important intersection.

outputFormat

Output a single integer via stdout denoting the minimum number of traffic lights required such that each important intersection is covered.

## sample
4 3 3
2 2
2 3
4 1
2