#P11134. 【MX-X5-T6】「GFOI Round 1」Abiogenesis
【MX-X5-T6】「GFOI Round 1」Abiogenesis
Background
Original link: https://oier.team/problems/X5G.
This problem is adapted from Codeforces 1981 E. Turtle and Intersected Segments.
Problem Description
You are given segments . The -th segment has a pair of weights .
There is an undirected graph that initially has vertices and edges. For every pair of positive integers such that , if segments and intersect, then add an edge in with endpoints and , and edge weight .
Find the sum of edge weights of a minimum spanning tree of , or report that is disconnected.
Two segments and are considered intersecting if .
Input Format
This problem has multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case:
The first line contains a positive integer , the number of segments.
Each of the next lines, the -th line contains four positive integers .
Output Format
For each test case, output one integer per line, the sum of edge weights of a minimum spanning tree of . In particular, if is disconnected, output .
4
5
1 7 1 3
2 4 2 6
3 5 3 5
6 7 2 9
3 4 1 4
5
2 7 3 3
1 3 5 6
4 5 3 5
6 7 1 9
1 1 5 4
4
1 4 1 3
1 2 2 1
3 4 3 5
1 4 4 4
3
1 3 1 1
2 3 1 3
4 5 1 8
22
41
17
-1
Hint
Sample Explanation
For the first test case, the graph looks like this:

One possible minimum spanning tree of looks like this:

Constraints
This problem uses bundled testdata and has subtask dependencies enabled.
| Subtask ID | Special Property | Dependencies | Score | ||
|---|---|---|---|---|---|
| None | None | ||||
| AC | |||||
| A | |||||
| B | None | ||||
| C | |||||
| D | None | ||||
| None |
- Special Property A: .
- Special Property B: $\forall i \in [1, n - 1], l_i \le l_{i + 1}, r_i \le r_{i + 1}$.
- Special Property C: .
- Special Property D: .
For all testdata, it holds that , , , and .
Translated by ChatGPT 5