#P9439. Crystal Imaging Analysis

    ID: 22591 Type: Default 1000ms 256MiB

Crystal Imaging Analysis

Crystal Imaging Analysis

You are part of a scientific team developing a new technique to image crystal structures at the molecular level. In the process, a very fine wind is blown over the surface of the crystal from several directions. For a wind blowing in direction \( (w_x, w_y) \), a boundary is defined as a location \( (x, y) \) such that a molecule exists at \( (x, y) \) and no molecule exists at \( (x-w_x, y-w_y) \). The experimental apparatus records, for each wind direction, a set of observed boundary locations.

The observations may be insufficient to uniquely determine the entire crystal structure. However, there are exactly two extremal structures that are consistent with all observations: one with the minimum and one with the maximum number of molecules. In this problem the extra molecules cannot be added arbitrarily because the following invariant must hold for each wind direction \( d=(w_x,w_y) \):

[ \text{For every molecule } (x,y) \text{ in the structure, } (x \in B_d) \iff ((x-w_x,y-w_y) \notin S). ]

The observed boundary set \( B_d \) for each wind is given, and the complete structure is known to lie within the bounding box of the observations. This means that when inferring additional molecules (to avoid creating an extra, unobserved boundary) you are only allowed to add molecules whose coordinates lie within the minimal and maximal \( x \) and \( y \) values seen in the input. Under these conditions the structure consistent with the observations is unique; hence the minimal and maximal molecule counts are equal.

Your task is to compute the total number of molecules in the crystal structure. Output two identical numbers — the minimal and the maximal possible number of molecules.

inputFormat

The first line contains an integer \( d \) representing the number of wind directions.

This is followed by \( d \) blocks of input. Each block begins with a line containing three integers: \( w_x \), \( w_y \) (the components of the wind direction) and \( k \), the number of observed boundary locations for that wind. Then follow \( k \) lines, each containing two integers \( x \) and \( y \), giving the coordinates of an observed boundary molecule.

All observed coordinates lie within a certain bounding box; the complete crystal is confined to this same box. When “back‐filling” molecules to satisfy the observations, do not add any molecule outside the bounding box.

outputFormat

Output two integers separated by a space: the minimal and maximal number of molecules in a structure consistent with the observations. (Under the given constraints these two numbers will be equal.)

sample

1
1 1 3
0 0
2 1
1 2
3 3