{"raw_statement":[{"iden":"problem statement","content":"You are given a connected undirected graph $G$ with $N$ vertices and $M$ edges. For each $i=1,2,\\ldots,M$, the $i$\\-th edge connects vertices $a_i$ and $b_i$, and is colored red if $c_i=$ `R` and blue if $c_i=$ `B`.\nDetermine if there is a spanning tree of $G$ that satisfies the following condition, and if so, display such a tree.\n\n*   For every $i=1,2,\\ldots,N$,\n    *   if $s_i = $ `R`, at least one red edge has vertex $i$ as its endpoint;\n    *   if $s_i = $ `B`, at least one blue edge has vertex $i$ as its endpoint."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $N-1 \\leq M \\leq 2 \\times 10^5$\n*   $1 \\leq a_i \\lt b_i \\leq N$\n*   $c_i$ is `R` or `B`.\n*   $(a_i,b_i,c_i) \\neq (a_j,b_j,c_j)$ if $i \\neq j$.\n*   The given graph is connected.\n*   $s_i$ is `R` or `B`.\n*   $N,M,a_i,b_i$ are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $M$\n$a_1$ $b_1$ $c_1$\n$\\vdots$\n$a_M$ $b_M$ $c_M$\n$s_1 s_2 \\ldots s_N$"},{"iden":"sample input 1","content":"3 3\n1 2 R\n1 3 B\n2 3 B\nRRB"},{"iden":"sample output 1","content":"Yes\n2 1\n\nHere we show that the spanning tree formed by the first and second edges of $G$ satisfies the condition.\n\n*   $s_1 = $ `R`, so for $i=1$, at least one red edge must have vertex $1$ as its endpoint. The first edge of $G$ is such an edge.\n*   $s_2 = $ `R`, so for $i=2$, at least one red edge must have vertex $2$ as its endpoint. The first edge of $G$ is such an edge.\n*   $s_3 = $ `B`, so for $i=3$, at least one blue edge must have vertex $3$ as its endpoint. The second edge of $G$ is such an edge."},{"iden":"sample input 2","content":"3 4\n1 2 R\n1 2 B\n1 3 B\n2 3 B\nRRR"},{"iden":"sample output 2","content":"No"},{"iden":"sample input 3","content":"8 16\n5 7 B\n2 7 R\n1 6 R\n1 4 R\n6 7 R\n4 6 B\n4 8 R\n2 3 R\n3 5 R\n6 7 B\n2 6 B\n5 6 R\n1 3 B\n4 5 B\n2 7 B\n1 8 B\nBRBRRBRB"},{"iden":"sample output 3","content":"Yes\n1 2 4 9 11 13 16"},{"iden":"sample input 4","content":"8 10\n1 7 R\n1 3 B\n2 5 B\n2 8 R\n1 5 R\n3 6 R\n2 6 B\n3 4 B\n2 8 B\n4 6 B\nRRRBBBRB"},{"iden":"sample output 4","content":"No"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}