#K60552. Fence Construction Problem
Fence Construction Problem
Fence Construction Problem
You are given a set of trees, each represented by its coordinates on a 2D plane. A valid fence can be built if and only if every tree has a unique x-coordinate and a unique y-coordinate. In other words, no two trees should share the same x-value or the same y-value.
Formally, if the trees are represented as points ((x_i, y_i)) for (i = 1, 2, \ldots, n), the fence can be successfully built if: [ \forall i \neq j,; x_i \neq x_j \text{ and } y_i \neq y_j ]
Your task is to determine whether a fence can be built using the provided trees. Output "YES" if it is possible, or "NO" otherwise.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (n) ((1 \le n \le 10^5)), denoting the number of trees. Each of the following (n) lines contains two space-separated integers, (x) and (y) ((-10^9 \le x, y \le 10^9)), representing the coordinates of a tree.
outputFormat
The output is written to standard output (stdout). Print a single line containing "YES" if a fence can be built (i.e. if all trees have unique x and unique y coordinates), or "NO" otherwise.## sample
4
1 2
3 4
5 6
7 8
YES
</p>