[Solution] Madoka and The First Session Codeforces Solution
Oh no, on the first exam Madoka got this hard problem:
Given integer and pairs of integers (). Also there is an array , initially filled with zeros.
Then for each index , where , perform either and , or and . Note that exactly one of these operations should be performed for every .
Also there is an array of length consisting of and . And there is an array , where it is guaranteed, that if holds, then .
Help Madoka and determine whenever it is possible to perform operations in such way that for every , where it holds that . If it possible you should also provide Madoka with a way to perform operations.
The first line contains two integers and () — the length of the array and the number of pair of integers.
The second line contains integers () — the elements of the array .
The third line contains integers () — the elements of the array . It is guaranteed that if holds, then .
-th of the following lines contains two integers and () — the indexes of the elements of the array to which the operation is performed. It is also guaranteed that there are no two indices and , where , such that or .
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 pairs of integers. If for pair we should perform and , print . Otherwise print . 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