Alone in the Cactus
시간 제한2초메모리 제한256 MB
선인장 그래프에서 s부터 무작위로 자기회피 경로를 따라 이동하다 파란 정점에서 재시작하고 빨강이나 초록에서 멈출 때, 빨간 정점에서 멈출 확률을 1e9+7로 나눈 값으로 구한다.
문제
Cactus is a connected undirected graph in which every edge belongs to at most one simple cycle.
You are given a cactus having vertices and edges. Each vertex of this cactus is either red, green or blue. All the vertices are numbered with sequential positive integers from to . The examples of such graphs are shown in the figure:

Initially, you are standing at the vertex . Then you start to move to some adjacent vertex, which hasn't been visited before, until no such vertex exists. The choice of each eligible vertex is equiprobable. When there is no such vertex, you are stopped at some vertex . If is colored red or green --- the process is stopped. If is colored blue --- the process should be restarted from the vertex again.
You are to write the program that for given cactus computes the probability that the process will be stopped when you are standing at a red vertex and outputs integer (). Here is a modular multiplicative inverse of an integer modulo .
입력
The first line of input contains three space-separated integers , and (, , ). The second line of input contains characters, -th of them denotes the color of vertex : 'R' denotes red, 'G' --- green and 'B' --- blue. Each of the following lines contains two integers , --- the numbers of vertices connected by the edge ().
It is guaranteed that the given graph is a cactus and it contains no multiple edges.
출력
The only line of output must contain one integer . If the process is infinite, output "NaN" instead (quotes for clarity).
힌트
Both samples correspond to the image in the statement. The first sample corresponds to the left cactus and the second sample --- corresponds to the right one.