#C7088. Graph Connectivity by Color

    ID: 50920 Type: Default 1000ms 256MiB

Graph Connectivity by Color

Graph Connectivity by Color

You are given an undirected graph \( G=(V,E) \) with \( n \) vertices and \( m \) edges. Each vertex is assigned a color which is either R (red) or B (blue). You need to answer \( q \) queries. In each query, given two vertices \( u \) and \( v \), determine whether there exists a path from \( u \) to \( v \) such that every vertex on the path, including \( u \) and \( v \), is of the same color. In other words, if \( u \) and \( v \) share the same color and belong to the same connected component (when considering only vertices of that color), output yes; otherwise, output no.

Note: The vertices are numbered from 1 to \( n \).

inputFormat

The input begins with an integer \( T \) denoting the number of test cases. For each test case:

  1. The first line contains two integers \( n \) and \( m \) representing the number of vertices and edges respectively.
  2. The second line contains a string of length \( n \) where each character is either R or B, indicating the color of each vertex.
  3. The next \( m \) lines each contain two integers \( u \) and \( v \) representing an undirected edge between vertices \( u \) and \( v \).
  4. The following line contains an integer \( q \) denoting the number of queries.
  5. The next \( q \) lines each contain two integers \( u \) and \( v \), representing a query.

outputFormat

For each query, print a single line containing yes if there exists a path between the two vertices comprising solely of vertices of the same color; otherwise, print no.

## sample
1
5 6
RBRRR
1 2
1 3
2 4
3 4
4 5
3 5
3
1 5
2 3
1 4
yes

no yes

</p>