GUPTA MECHANICAL

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

Friday 2 September 2022

[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 (vi,ui). Also there is an array b1,b2,,bninitially filled with zeros.

Then for each index i, where 1im, perform either bvi:=bvi1 and bui:=bui+1, or bvi:=bvi+1 and bui:=bui1. 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 a1,a2,,an, where it is guaranteed, that if si=0 holds, then ai=0.

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

Input

The first line contains two integers n and m (2n10000,1m10000) — the length of the array a and the number of pair of integers.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

The second line contains n integers s1,s2,sn (0si1) — the elements of the array s.

The third line contains n integers a1,a2,,an (|ai|m) — the elements of the array a. It is guaranteed that if si=0 holds, then ai=0.

i-th of the following m lines contains two integers vi and ui (1vi,uin,viui) — 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 1i<jm, such that (vi,ui)=(vj,uj) or (vi,ui)=(uj,vj).

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 (vi,ui) we should perform bvi:=bvi1 and bui:=bui+1, print (vi,ui). Otherwise print (ui,vi). If there are multiple ways to get the correct answer, you can print any of them.

You can print pairs in any order.

No comments:

Post a Comment