Graph and Machine

아직 제출이 없습니다시간 제한4초메모리 제한512 MB

문제

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 00 or 11 on each of its vertices. The machine was something more peculiar.

A machine of order nn 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 00 and the other is labeled with 11. Each of the remaining vertices including the source is labeled with an integer from 1,,n\\{1, \ldots, n\\} and has exactly two outer edges: one labeled with 00 and the other labeled with 11. Also on every path from the source to a sink, all labels of the non-sink vertices are distinct

A machine of order nn computes a function from 0,1n\\{0,1\\}^n to 0,1\\{0,1\\}. Let us define it recursively. For 00-sink, the function is 00 on every input, for 11-sink, it is 11 for every input. For a non-sink vertex vv labeled with ii, f_v(x_1,,x_n)={f_t_0(x_1,,x_n)if x_i=0 f_t_1(x_1,,x_n)if x_i=1f\_v(x\_1, \ldots, x\_n) = \begin{cases} f\_{t\_0} (x\_1, \ldots, x\_n) & \text{if } x\_i = 0 \\\ f\_{t\_1} (x\_1, \ldots, x\_n) & \text{if } x\_i = 1 \end{cases} where t_jt\_j is the end of the edge from vv labeled with jj for j0,1j \in \\{0,1\\}. The function calculated by a machine with the source ss is f_sf\_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)\mathrm{EC}(x\_1, \ldots, x\_m) of a colored graph GG with \ell vertices and mm edges with vertex-labels c_1,,c_c\_1, \ldots, c\_{\ell} is a function from 0,1m\\{0,1\\}^m to 0,1\\{0,1\\}. It equals 11 if and only if for every vertex vv with incident edges e_1,,e_ke\_1, \ldots, e\_k, the following equality holds: c_v=_i=1kx_e_ic\_v = \bigoplus\limits\_{i=1}^k x\_{e\_i}. In other words, the parity of the sum of values on edges incident to vv is c_vc\_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 xx such that EC(x)f(x)\mathrm{EC}(x) \neq f(x), where ff is the function calculated by the machine.

입력

The first line contains five integers NN, mm, ss, t_0t\_0, and t_1t\_1: the number of nodes in the machine, the order of the machine, the index of the source and the indices of the 00-sink and 11-sink respectively (1s,t_0,t_1N300,0001 \le s, t\_0, t\_1 \le N \le 300\\,000; N3N \ge 3; 1m300,0001 \le m \le 300\\,000; t_0t_1t\_0 \neq t\_1; st_0s \neq t\_0; st_1s \neq t\_1). The ii-th of the next NN lines describes the ii-th node of the machine. It contains three integers o_0o\_0, o_1o\_1 and \ell: the index of the end node of the outer edge from the node ii labeled with 00, this index for the edge labeled with 11, and the label of the node ii itself (1o_0,o_1N-1 \le o\_0, o\_1 \le N; 1m-1 \le \ell \le m). If ii is a sink, o_0=o_1==1o\_0 = o\_1 = \ell = -1. The values o_0o\_0, o_1o\_1 and \ell are never equal to zero.

It is guaranteed that

  • the graph of the machine is acyclic;
  • o_0o\_0, o_1o\_1 or \ell are equal to 1-1 if and only if the node is a sink;
  • on every path from the source to a sink, all labels of non-sink vertices are unique;
  • all vertices except maybe one of the sinks are reachable from ss.

The next line contains one integer kk, the number of vertices in the colored graph GG (1k300,0001 \le k \le 300\\,000). The number of edges in this graph is mm. The following line contains kk integers c_1,c_2,,c_kc\_1, c\_2, \ldots, c\_k, the labels of the vertices of GG (each c_ic\_i is either 00 or 11).

The last mm lines contain descriptions of the edges of GG. The ii-th of these lines contains two integers a_ia\_i and b_ib\_i which describe an edge connecting a_ia\_i and b_ib\_i (1a_i,b_ik1 \le a\_i, b\_i \le k; a_ib_ia\_i \neq b\_i). It is guaranteed that GG 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 mm characters x_1,x_2,,x_mx\_1, x\_2, \ldots, x\_m such that EC(x_1,x_2,,x_m)f(x_1,x_2,,x_m)\mathrm{EC}(x\_1, x\_2, \ldots, x\_m) \neq f(x\_1, x\_2, \ldots, x\_m), where ff is the function computed by the machine. Each x_ix\_i must be either 00 or 11.