All Tracks Algorithms Graphs Problem

Childhood Games
Tag(s):

Easy

Problem
Editorial
Analytics

Sunny loves playing childhood games even he is professional. Today he remembers a game in which we have to draw a shape without lifting our pencil. The description of shape that he has is a series of curved non-overlapping lines. You have to just print YES in case its possible to draw the shape without lifting pencil or else print NO.

YOU CAN NOT TRACE A LINE TWICE

Input
First line contains a number $$N$$ as input which is total number of line segments in the shape.
Each of the next $$N$$ lines contain description of each non overlapping curve in the form $$x_1, y_1, x_2, y_2$$ which means curve connects points $$(x_1,y_1)$$ and $$(x_2,y_2)$$ in the x-y plane

Output
Output YES if the shape can be drawn without lifting the pencil or else print NO

Constraints
$$1 \le N \le 10^5$$
$$1 \le x_1, y_1, x_2, y_2 \le 10^9$$

SAMPLE INPUT
5 
1 1 2 1
2 1 2 2
2 2 1 1
1 1 1 2
1 2 2 1
SAMPLE OUTPUT
YES
Explanation

The shape formed here is depicted in the image and you can make it without lifting pencil if you start from (2,1) -> (1,2) -> (1,1) -> (2,2) - > (2,1) - >(1,1)

enter image description here

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

Notifications
View All Notifications