407647: GYM102862 K Binary Sequence

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Binary Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given a sequence of $$$n$$$ bits $$$a_1$$$, $$$\ldots$$$, $$$a_n$$$ (each bit can be either $$$0$$$ or $$$1$$$). Initially all bits are set to $$$0$$$. You are also given $$$m$$$ pairs of indices $$$(i,j)$$$, which are the possible operations you can apply to the sequence. If you apply an operation $$$(i,j)$$$, $$$a_i$$$ changes to $$$1-a_i$$$ and $$$a_j$$$ to $$$1-a_j$$$.

You are also given a target sequence of $$$n$$$ bits $$$b_1$$$, $$$\ldots$$$, $$$b_n$$$. Determine if it is possible to obtain $$$b$$$ from $$$a$$$ by applying the available operations (you can also not change the array at all). Each operation can be applied zero or multiple times, and operations may be appplied in any order.

Input

The first line of input contains a single integer, the value of $$$n$$$ ($$$2 \leq n \leq 10^5$$$). The following line contains $$$n$$$ bits $$$b_1$$$, $$$\ldots$$$, $$$b_n$$$ ($$$0 \leq b_i \leq 1$$$).

The next line contains a single integer, the value of $$$m$$$ ($$$1 \leq m \leq 10^5$$$). The next $$$m$$$ lines each contains two integers $$$l_i$$$ and $$$r_i$$$, the indexes of an operation ($$$1 \leq l_i < r_i \leq n$$$). No two operations are equal.

Output

Output "Yes", if it is possible, and "No" otherwise.

ExamplesInput
5
1 1 0 1 1
3
1 3
3 4
2 5
Output
Yes
Input
2
0 1
1
1 2
Output
No

加入题单

上一题 下一题 算法标签: