#T60. 连接格点
连接格点
Description
There is a point grid with M rows and N columns, where adjacent points can be connected. A vertical connection costs one unit, and a horizontal connection costs two units. Some points are already connected. Determine the minimum additional cost required to ensure all points are fully connected.
Input Format
The first line contains two positive integers, m and n.
The following lines each contain four positive integers: , indicating that the point at row , column is already connected to the point at row , column . The input guarantees that .
Output Format
Output the minimum additional cost required to connect all the points.
2 2
1 1 2 1
3
Hint
【Data Scale】
30% of the data: n*m ≤ 1000
100% of the data: m, n ≤ 1000