The positive numbers can be envisioned as opening sections and the negative numbers as shutting sections, where coordinating with sections should have a similar kind (outright worth). For instance, [1,2,−2,−1] and [1,3,−3,2,−2,−1] are adjusted, however [1,2,−1,−2] and [−1,1] are not adjusted.    There are 2n cards. Each card has a number on the front and a number on the back. Every integer 1,−1,2,−2,… ,n,−n shows up precisely once on the facade of some card and precisely once on the rear of a few (not really the equivalent) card.    You can reorder the cards anyway you like. You are not permitted to flip cards, so numbers can't move between the front and back. Your errand is to arrange the cards so the successions given by the front numbers and the back numbers are both adjusted, or report that it is incomprehensible.    Input    The principal line contains a solitary integer n (1≤n≤2⋅105) — the number of section types, and a large portion of the number of cards.    The following 2n lines depict the cards. The I-th of these lines contains two integers man-made intelligence, bi (−n≤ai,bi≤n, ai≠0, bi≠0) — the numbers on the front and back of the I-th card, individually. Each integer 1,−1,2,−2,… ,n,−n shows up precisely once as man-made intelligence and precisely once as bi.    Output    On the principal line, output "YES" in case it's feasible to reorder these cards to fulfill the condition. In any case, output "NO". You can print each letter regardless (upper or lower).

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Correct answer will be upvoted else downvoted. Computer science.

 

 The positive numbers can be envisioned as opening sections and the negative numbers as shutting sections, where coordinating with sections should have a similar kind (outright worth). For instance, [1,2,−2,−1] and [1,3,−3,2,−2,−1] are adjusted, however [1,2,−1,−2] and [−1,1] are not adjusted. 

 

There are 2n cards. Each card has a number on the front and a number on the back. Every integer 1,−1,2,−2,… ,n,−n shows up precisely once on the facade of some card and precisely once on the rear of a few (not really the equivalent) card. 

 

You can reorder the cards anyway you like. You are not permitted to flip cards, so numbers can't move between the front and back. Your errand is to arrange the cards so the successions given by the front numbers and the back numbers are both adjusted, or report that it is incomprehensible. 

 

Input 

 

The principal line contains a solitary integer n (1≤n≤2⋅105) — the number of section types, and a large portion of the number of cards. 

 

The following 2n lines depict the cards. The I-th of these lines contains two integers man-made intelligence, bi (−n≤ai,bi≤n, ai≠0, bi≠0) — the numbers on the front and back of the I-th card, individually. Each integer 1,−1,2,−2,… ,n,−n shows up precisely once as man-made intelligence and precisely once as bi. 

 

Output 

 

On the principal line, output "YES" in case it's feasible to reorder these cards to fulfill the condition. In any case, output "NO". You can print each letter regardless (upper or lower).

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY