## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Madoka and The First Session Codeforces Solution

F. Madoka and The First Session
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Given integer $n$ and $m$ pairs of integers (${v}_{i},{u}_{i}$). Also there is an array ${b}_{1},{b}_{2},\dots ,{b}_{n}$initially filled with zeros.

Then for each index $i$, where $1\le i\le m$, perform either ${b}_{{v}_{i}}:={b}_{{v}_{i}}-1$ and ${b}_{{u}_{i}}:={b}_{{u}_{i}}+1$, or ${b}_{{v}_{i}}:={b}_{{v}_{i}}+1$ and ${b}_{{u}_{i}}:={b}_{{u}_{i}}-1$. Note that exactly one of these operations should be performed for every $i$.

Also there is an array $s$ of length $n$ consisting of $0$ and $1$. And there is an array ${a}_{1},{a}_{2},\dots ,{a}_{n}$, where it is guaranteed, that if ${s}_{i}=0$ holds, then ${a}_{i}=0$.

Help Madoka and determine whenever it is possible to perform operations in such way that for every $i$, where ${s}_{i}=1$ it holds that ${a}_{i}={b}_{i}$. If it possible you should also provide Madoka with a way to perform operations.

Input

The first line contains two integers $n$ and $m$ ($2\le n\le 10000,1\le m\le 10000$) — the length of the array $a$ and the number of pair of integers.

Solution Click Below:-  👉
👇👇👇👇👇

The second line contains $n$ integers ${s}_{1},{s}_{2},\dots {s}_{n}$ ($0\le {s}_{i}\le 1$) — the elements of the array $s$.

The third line contains $n$ integers ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($|{a}_{i}|\le m$) — the elements of the array $a$. It is guaranteed that if ${s}_{i}=0$ holds, then ${a}_{i}=0$.

$i$-th of the following $m$ lines contains two integers ${v}_{i}$ and ${u}_{i}$ ($1\le {v}_{i},{u}_{i}\le n,{v}_{i}\ne {u}_{i}$) — the indexes of the elements of the array $b$ to which the operation is performed. It is also guaranteed that there are no two indices $i$ and $j$, where $1\le i, such that $\left({v}_{i},{u}_{i}\right)=\left({v}_{j},{u}_{j}\right)$ or $\left({v}_{i},{u}_{i}\right)=\left({u}_{j},{v}_{j}\right)$.

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 $m$ pairs of integers. If for pair $\left({v}_{i},{u}_{i}\right)$ we should perform ${b}_{{v}_{i}}:={b}_{{v}_{i}}-1$ and ${b}_{{u}_{i}}:={b}_{{u}_{i}}+1$, print $\left({v}_{i},{u}_{i}\right)$. Otherwise print $\left({u}_{i},{v}_{i}\right)$. If there are multiple ways to get the correct answer, you can print any of them.

You can print pairs in any order.