A13103 | Segment Tree
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
As the name of the task implies, you are asked to do some work with segments and trees.
Recall that a tree is a connected undirected graph such that there is exactly one simple path between every pair of its vertices.
You are given $n$ segments $[l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]$ , $l_i < r_i$ for every $i$ . It is guaranteed that all segments' endpoints are integers, and all endpoints are unique — there is no pair of segments such that they start in the same point, end in the same point or one starts in the same point the other one ends.
Let's generate a graph with $n$ vertices from these segments. Vertices $v$ and $u$ are connected by an edge if and only if segments $[l_v, r_v]$ and $[l_u, r_u]$ intersect and neither of it lies fully inside the other one.
For example, pairs $([1, 3], [2, 4])$ and $([5, 10], [3, 7])$ will induce the edges but pairs $([1, 2], [3, 4])$ and $([5, 7], [3, 10])$ will not.
Determine if the resulting graph is a tree or not.
Recall that a tree is a connected undirected graph such that there is exactly one simple path between every pair of its vertices.
You are given $n$ segments $[l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]$ , $l_i < r_i$ for every $i$ . It is guaranteed that all segments' endpoints are integers, and all endpoints are unique — there is no pair of segments such that they start in the same point, end in the same point or one starts in the same point the other one ends.
Let's generate a graph with $n$ vertices from these segments. Vertices $v$ and $u$ are connected by an edge if and only if segments $[l_v, r_v]$ and $[l_u, r_u]$ intersect and neither of it lies fully inside the other one.
For example, pairs $([1, 3], [2, 4])$ and $([5, 10], [3, 7])$ will induce the edges but pairs $([1, 2], [3, 4])$ and $([5, 7], [3, 10])$ will not.
Determine if the resulting graph is a tree or not.
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 5 \cdot 10^5$ ) — the number of segments.
The $i$ -th of the next $n$ lines contain the description of the $i$ -th segment — two integers $l_i$ and $r_i$ ( $1 \le l_i < r_i \le 2n$ ).
It is guaranteed that all segments borders are pairwise distinct.
The $i$ -th of the next $n$ lines contain the description of the $i$ -th segment — two integers $l_i$ and $r_i$ ( $1 \le l_i < r_i \le 2n$ ).
It is guaranteed that all segments borders are pairwise distinct.
输出格式
Print "YES" if the resulting graph is a tree and "NO" otherwise.
输入输出样例
输入 #1
6 9 12 2 11 1 3 6 10 5 7 4 8
输出 #1
YES
输入 #2
5 1 3 2 4 5 9 6 8 7 10
输出 #2
NO
输入 #3
5 5 8 3 6 2 9 7 10 1 4
输出 #3
NO
The graph corresponding to the first example:

The graph corresponding to the second example:

The graph corresponding to the third example:


The graph corresponding to the second example:

The graph corresponding to the third example:

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted