CF471E.MUH and Lots and Lots of Segments
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to do some painting. As they were trying to create their first masterpiece, they made a draft on a piece of paper. The draft consists of n segments. Each segment was either horizontal or vertical. Now the friends want to simplify the draft by deleting some segments or parts of segments so that the final masterpiece meets three conditions:
- Horace wants to be able to paint the whole picture in one stroke: by putting the brush on the paper and never taking it off until the picture is ready. The brush can paint the same place multiple times. That's why all the remaining segments must form a single connected shape.
- Menshykov wants the resulting shape to be simple. He defines a simple shape as a shape that doesn't contain any cycles.
- Initially all the segment on the draft have integer startpoint and endpoint coordinates. Uslada doesn't like real coordinates and she wants this condition to be fulfilled after all the changes.
As in other parts the draft is already beautiful, the friends decided to delete such parts of the draft that the sum of lengths of the remaining segments is as large as possible. Your task is to count this maximum sum of the lengths that remain after all the extra segments are removed.
圣彼得堡动物园的北极熊门什科夫(Menshykov)和乌斯拉达(Uslada),以及基辅动物园的大象霍勒斯(Horace)决定一起进行绘画创作。在尝试创作他们的第一幅杰作时,他们在一张纸上绘制了一幅草图。该草图由 n 条线段组成,每条线段均为水平或垂直方向。现在,这几位朋友希望通过对草图删除某些线段或线段的一部分来简化它,使得最终作品满足以下三个条件:
- 霍勒斯希望整幅画能一笔画成:即画笔一旦落于纸上,便不再抬起,直至整幅画完成。画笔可以多次经过同一位置。因此,所有剩余线段必须构成一个连通图形。
- 门什科夫希望最终图形是“简单”的。他将“简单图形”定义为不含任何环(cycle) 的图形。
- 草图中所有线段的起点与终点坐标初始均为整数。乌斯拉达不喜欢实数坐标,因此她要求所有修改完成后,剩余线段的所有端点坐标仍为整数。
由于草图其余部分已十分精美,朋友们决定仅删除尽可能少长度的部分,即保留剩余线段的总长度最大。你的任务是计算在满足上述所有条件的前提下,所能保留的线段长度之和的最大值。
输入格式
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of segments on the draft. The next n lines contain four integers each: _x_1, _y_1, _x_2, _y_2 ( - 109 ≤ _x_1 ≤ _x_2 ≤ 109; - 109 ≤ _y_1 ≤ _y_2 ≤ 109) — the two startpoint and the two endpoint coordinates of a segment. All segments are non-degenerative and either are strictly horizontal or strictly vertical.
No two horizontal segments share common points. No two vertical segments share common points.
输入的第一行包含一个整数 $ n ( 1 \leq n \leq 2 \cdot 10^5 $)—— 表示草图中线段的数量。接下来的 $ n $ 行每行包含四个整数:$ x_1, y_1, x_2, y_2 ( -10^9 \leq x_1 \leq x_2 \leq 10^9 ; -10^9 \leq y_1 \leq y_2 \leq 10^9 $)—— 分别表示某一线段的两个端点坐标。所有线段均为非退化线段,且要么严格水平,要么严格垂直。
任意两条水平线段不相交(即无公共点)。任意两条垂直线段不相交(即无公共点)。
输出格式
Print a single integer — the maximum sum of lengths for the remaining segments.
输出一个整数——剩余线段长度之和的最大值。
输入输出样例
输入#1
2 0 0 0 1 1 0 1 1
输出#1
1
输入#2
4 0 0 1 0 0 0 0 1 1 -1 1 2 0 1 1 1
输出#2
5
说明/提示
The shapes that you can get in the two given samples are:

In the first sample you need to delete any segment as the two segments together do not form a single connected shape.
In the second sample the initial segments form a cycle, there are four ways to break the cycle: delete the first, second or fourth segment altogether or delete the middle of the third segment. The last way is shown on the picture.
在给定的两个样例中,可以得到的图形如下:

在第一个样例中,你需要删除任意一条线段,因为这两条线段合在一起并不能构成一个单一的连通图形。
在第二个样例中,初始的线段构成一个环;共有四种方式可将其断开:完全删除第一条、第二条或第四条线段,或者仅删除第三条线段的中间部分。图中展示的是最后一种方式。
输入解题思路,AI测评打分。不知道怎么写?