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).
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≤
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).
Step by step
Solved in 4 steps with 1 images