#P1717F. Madoka and The First Session

    ID: 875 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 9 Uploaded By: Tags>constructive algorithmsflowsgraph matchingsgraphsimplementation*2500

Madoka and The First Session

Description

Oh no, on the first exam Madoka got this hard problem:

Given integer nn and mm pairs of integers (vi,uiv_i, u_i). Also there is an array b1,b2,,bnb_1, b_2, \ldots, b_n, initially filled with zeros.

Then for each index ii, where 1im1 \leq i \leq m, perform either bvi:=bvi1b_{v_i} := b_{v_i} - 1 and bui:=bui+1b_{u_i} := b_{u_i} + 1, or bvi:=bvi+1b_{v_i} := b_{v_i} + 1 and bui:=bui1b_{u_i} := b_{u_i} - 1. Note that exactly one of these operations should be performed for every ii.

Also there is an array ss of length nn consisting of 00 and 11. And there is an array a1,a2,,ana_1, a_2, \ldots, a_n, where it is guaranteed, that if si=0s_i = 0 holds, then ai=0a_i = 0.

Help Madoka and determine whenever it is possible to perform operations in such way that for every ii, where si=1s_i = 1 it holds that ai=bia_i = b_i. If it possible you should also provide Madoka with a way to perform operations.

The first line contains two integers nn and mm (2n10000,1m100002 \leq n \leq 10000, 1 \leq m \leq 10000) — the length of the array aa and the number of pair of integers.

The second line contains nn integers s1,s2,sns_1, s_2, \ldots s_n (0si10 \le s_i \le 1) — the elements of the array ss.

The third line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (aim|a_i| \leq m) — the elements of the array aa. It is guaranteed that if si=0s_i = 0 holds, then ai=0a_i = 0.

ii-th of the following mm lines contains two integers viv_i and uiu_i (1vi,uin,viui1 \leq v_i, u_i \leq n, v_i \ne u_i) — the indexes of the elements of the array bb to which the operation is performed. It is also guaranteed that there are no two indices ii and jj, where 1i<jm1 \le i < j \le m, such that (vi,ui)=(vj,uj)(v_i, u_i) = (v_j, u_j) or (vi,ui)=(uj,vj)(v_i, u_i) = (u_j, v_j).

In the first line print "YES" if it is possible to perform operations in the required way, and "NO" otherwise.

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

In case you printed "YES", print mm pairs of integers. If for pair (vi,ui)(v_i, u_i) we should perform bvi:=bvi1b_{v_i} := b_{v_i} - 1 and bui:=bui+1b_{u_i} := b_{u_i} + 1, print (vi,ui)(v_i, u_i). Otherwise print (ui,vi)(u_i, v_i). If there are multiple ways to get the correct answer, you can print any of them.

You can print pairs in any order.

Input

The first line contains two integers nn and mm (2n10000,1m100002 \leq n \leq 10000, 1 \leq m \leq 10000) — the length of the array aa and the number of pair of integers.

The second line contains nn integers s1,s2,sns_1, s_2, \ldots s_n (0si10 \le s_i \le 1) — the elements of the array ss.

The third line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (aim|a_i| \leq m) — the elements of the array aa. It is guaranteed that if si=0s_i = 0 holds, then ai=0a_i = 0.

ii-th of the following mm lines contains two integers viv_i and uiu_i (1vi,uin,viui1 \leq v_i, u_i \leq n, v_i \ne u_i) — the indexes of the elements of the array bb to which the operation is performed. It is also guaranteed that there are no two indices ii and jj, where 1i<jm1 \le i < j \le m, such that (vi,ui)=(vj,uj)(v_i, u_i) = (v_j, u_j) or (vi,ui)=(uj,vj)(v_i, u_i) = (u_j, v_j).

Output

In the first line print "YES" if it is possible to perform operations in the required way, and "NO" otherwise.

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

In case you printed "YES", print mm pairs of integers. If for pair (vi,ui)(v_i, u_i) we should perform bvi:=bvi1b_{v_i} := b_{v_i} - 1 and bui:=bui+1b_{u_i} := b_{u_i} + 1, print (vi,ui)(v_i, u_i). Otherwise print (ui,vi)(u_i, v_i). If there are multiple ways to get the correct answer, you can print any of them.

You can print pairs in any order.

Sample Input 1

5 5
1 1 1 1 1
-2 0 2 1 -1
1 5
1 4
3 5
3 4
4 5

Sample Output 1

YES
1 5
1 4
5 3
4 3
5 4

Sample Input 2

5 5
0 1 0 1 0
0 1 0 0 0
1 3
2 3
3 5
3 4
4 5

Sample Output 2

YES
3 1
3 2
5 3
3 4
4 5

Sample Input 3

4 4
1 1 1 1
0 2 -2 2
1 3
1 4
2 3
2 4

Sample Output 3

NO

Note

In the first example, the array bb will change as follows: [0,0,0,0,0][1,0,0,1,0][2,0,0,1,1][2,0,1,0,1][2,0,2,0,0][2,0,2,1,1][0,0,0,0,0] \rightarrow [-1,0,0,1,0] \rightarrow [-2,0,0,1,1] \rightarrow [-2,0,1,0,1] \rightarrow [-2,0,2,0,0] \rightarrow [-2,0,2,1,-1]. ai=bia_i = b_i for all indices ii from 11 to 55.

In the second example, it is enough for us that b2=1b_2 = 1 at the end, since only s2=1s_2 = 1.

In the third example, the operations cannot be performed as required.