Score : $400$ points
Given is a simple undirected graph with $N$ vertices and $M$ edges. The $i$-th edge connects Vertex $c_i$ and Vertex $d_i$. Initially, Vertex $i$ has the value $a_i$ written on it. You want to change the values on Vertex $1$, $\ldots$, Vertex $N$ to $b_1$, $\cdots$, $b_N$, respectively, by doing the operation below zero or more times.
Determine whether it is possible to achieve the objective by properly doing the operation.
Input is given from Standard Input in the following format:
$N$ $M$ $a_1$ $\cdots$ $a_N$ $b_1$ $\cdots$ $b_N$ $c_1$ $d_1$ $\vdots$ $c_M$ $d_M$
Print Yes
if it is possible to achieve the objective by properly doing the operation, and No
otherwise.
3 2 1 2 3 2 2 2 1 2 2 3
Yes
You can achieve the objective by, for example, doing the operation as follows:
This sequence of operations makes $a_1=2$, $a_2=2$, and $a_3=2$.
1 0 5 5
Yes
The objective may be achieved already in the beginning.
2 1 1 1 2 1 1 2
No
There is no way to do the operation to achieve the objective.
17 9 -905371741 -999219903 969314057 -989982132 -87720225 -175700172 -993990465 929461728 895449935 -999016241 782467448 -906404298 578539175 9684413 -619191091 -952046546 125053320 -440503430 -997661446 -912471383 -995879434 932992245 -928388880 -616761933 929461728 210953513 -994677396 648190629 -530944122 578539175 9684413 595786809 -952046546 125053320 2 10 6 12 9 11 11 5 7 6 3 15 3 1 1 9 10 4
Yes