Connecting Boxes
Practice
4.2 (4 votes)
Medium
Problem
77% Success 1159 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Problem:

N boxes are arranged systematically in a circle and numbered from 1 to N in increasing order in clockwise direction. There will be Q queries asking you whether boxes i and j can be connected by a straight rod such that this rod does not intersect ( criss - cross as seen from top view ) with any of the other rods used to join other boxes in the previous queries. If the rod does not intersect with any of the other rods, the boxes i and j will be connected by the rod , or else the connection will not be made. Every box can be connected to at most one other box. No box can be connected to itself. Infinitley many rods of all possible sizes are available.

Input:

First line comprises of two space separated integers N and Q. Then there will be Q lines, each line will consist of two space separated integers i and j.

Output:

Print the answer to each query , 'YES' if the connection can be made and 'NO' if the connection cannot be made.

Constraints:

\(2<=N<=1000\)

\(1<=Q<=1000\)

\(1<=i,j<=N\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
2 votes
Tags:
MathematicsMediumMathematicsMathematicsMathamatics
Points:30
1 votes
Tags:
Ad-HocOpenAlgorithmsApprovedMediumMathamatics
Points:30
Tags:
Dynamic ProgrammingProbabilityCombinatoricsAd-HocMediumMathematicsOpenApprovedMathamatics