John's father recently passed away and left John a colored graph and a machine. The colored graph was simply a connected undirected graph with labels 0 or 1 on each of its vertices. The machine was something more peculiar.
A machine of order n is an acyclic directed graph with one source (a vertex with no incoming edges) and two sinks (vertices with no outgoing edges). One of the sinks is labeled with 0 and the other is labeled with 1. Each of the remaining vertices including the source is labeled with an integer from 1,…,n and has exactly two outer edges: one labeled with 0 and the other labeled with 1. Also on every path from the source to a sink, all labels of the non-sink vertices are distinct.
A machine of order n computes a function from 0,1n to 0,1. Let us define it recursively. For 0-sink, the function is 0 on every input, for 1-sink, it is 1 for every input. For a non-sink vertex v labeled with i, f_v(x_1,…,x_n)={f_t_0(x_1,…,x_n) f_t_1(x_1,…,x_n)if x_i=0if x_i=1 where t_j is the end of the edge from v labeled with j for j∈0,1. The function calculated by a machine with the source s is f_s.
In his will, Jonh's father wrote that he had worked on the machine for years in order to calculate the edge-coloring function of the colored graph he had given to John. All he asks John is to check if the machine calculates this function correctly.
The edge-coloring function EC(x_1,…,x_m) of a colored graph G with ℓ vertices and m edges with vertex-labels c_1,…,c_ℓ is a function from 0,1m to 0,1. It equals 1 if and only if for every vertex v with incident edges e_1,…,e_k, the following equality holds: c_v=⨁_i=1kx_e_i. In other words, the parity of the sum of values on edges incident to v is c_v.
You are asked to check if the given machine calculates the edge-coloring function of the given graph, and if it is not, find the coloring of edges x such that EC(x)=f(x), where f is the function calculated by the machine.
The first line contains five integers N, m, s, t_0, and t_1: the number of nodes in the machine, the order of the machine, the index of the source and the indices of the 0-sink and 1-sink respectively (1≤s,t_0,t_1≤N≤300,000; N≥3; 1≤m≤300,000; t_0=t_1; s=t_0; s=t_1). The i-th of the next N lines describes the i-th node of the machine. It contains three integers o_0, o_1 and ℓ: the index of the end node of the outer edge from the node i labeled with 0, this index for the edge labeled with 1, and the label of the node i itself (−1≤o_0,o_1≤N; −1≤ℓ≤m). If i is a sink, o_0=o_1=ℓ=−1. The values o_0, o_1 and ℓ are never equal to zero.
It is guaranteed that
The next line contains one integer k, the number of vertices in the colored graph G (1≤k≤300,000). The number of edges in this graph is m. The following line contains k integers c_1,c_2,…,c_k, the labels of the vertices of G (each c_i is either 0 or 1).
The last m lines contain descriptions of the edges of G. The i-th of these lines contains two integers a_i and b_i which describe an edge connecting a_i and b_i (1≤a_i,b_i≤k; a_i=b_i). It is guaranteed that G is connected, but it may contain parallel edges.
Print "YES" on the first line if the machine calculates the edge-coloring function correctly. Otherwise, print "NO" on the first line, and on the next line, print m characters x_1,x_2,…,x_m such that EC(x_1,x_2,…,x_m)=f(x_1,x_2,…,x_m), where f is the function computed by the machine. Each x_i must be either 0 or 1.