#P5998. Merging Tribes
Merging Tribes
Merging Tribes
In ancient times, there were $n$ tribes in the Kingdom of Jili. Each tribe was represented by an axis-aligned rectangle. Note that some regions might belong to multiple tribes.
Over time, if two tribes have a common overlapping area (i.e. intersection area strictly greater than zero), they merge into a new tribe. The new tribe is represented by the smallest axis-aligned rectangle that contains both original tribes. This process continues until no two tribes can merge.
Input Format: The first line contains an integer $n$. Each of the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$, $y_2$, representing the bottom-left and top-right coordinates of a tribe's rectangle (with $x_1 < x_2$ and $y_1 < y_2$).
Output Format: First, output a single integer denoting the number of tribes remaining after all mergers. Then, output the coordinates of each tribe's rectangle on a separate line as four integers: $x_{\min}$, $y_{\min}$, $x_{\max}$, $y_{\max}$. The order of the tribes does not matter.
inputFormat
The first line contains an integer (). Each of the following lines contains four integers , , , ( with and ), representing a tribe's rectangle.
outputFormat
First, output an integer representing the number of remaining tribes. Then, for each tribe, output a line with four integers: , , , , which are the coordinates of the merged rectangle that covers all rectangles in that tribe.
sample
4
1 1 3 3
2 2 4 4
5 5 6 6
3 1 4 2
2
1 1 4 4
5 5 6 6
</p>