CF1278D.Segment Tree
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 [l1,r1],[l2,r2],…,[ln,rn] , li<ri 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 [lv,rv] and [lu,ru] 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≤n≤5⋅105 ) — the number of segments.
The i -th of the next n lines contain the description of the i -th segment — two integers li and ri ( 1≤li<ri≤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: