아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Alone in the Cactus

시간 제한2초메모리 제한256 MB

요약
선인장 그래프에서 s부터 무작위로 자기회피 경로를 따라 이동하다 파란 정점에서 재시작하고 빨강이나 초록에서 멈출 때, 빨간 정점에서 멈출 확률을 1e9+7로 나눈 값으로 구한다.
난이도

보통10점 중 7점

유형
그래프, DFS, 확률, 수학
정답자
아직 제출이 없습니다

문제

Cactus is a connected undirected graph in which every edge belongs to at most one simple cycle.

You are given a cactus having nn vertices and mm edges. Each vertex of this cactus is either red, green or blue. All the vertices are numbered with sequential positive integers from 11 to nn. The examples of such graphs are shown in the figure:

Initially, you are standing at the vertex ss. 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 tt. If tt is colored red or green --- the process is stopped. If tt is colored blue --- the process should be restarted from the vertex ss again.

You are to write the program that for given cactus computes the probability pq\frac{p}{q} that the process will be stopped when you are standing at a red vertex and outputs integer p⋅q−1mod  1000000007p \cdot q^{-1} \mod 1000000007 (109+710^{9}+7). Here q−1q^{-1} is a modular multiplicative inverse of an integer qq modulo 10000000071000000007.

입력

The first line of input contains three space-separated integers nn, mm and ss (2≤n≤1052 \leq n \leq 10^{5}, m≥n−1m \geq n - 1, 1≤s≤n1 \leq s \leq n). The second line of input contains nn characters, ii-th of them denotes the color of vertex ii: 'R' denotes red, 'G' --- green and 'B' --- blue. Each of the following mm lines contains two integers u_iu\_{i}, v_iv\_{i} --- the numbers of vertices connected by the edge (1≤u_i,v_i≤n1 \leq u\_{i}, v\_{i} \leq n).

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 p⋅q−1 mod 109+7p \cdot q^{-1} \bmod 10^9+7. 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.

예제2

  1. 예제 1

    입력
    6 6 1
    GRGRGB
    1 2
    1 3
    2 4
    3 4
    4 5
    4 6
    
    예상 출력
    250000002
    
  2. 예제 2

    입력
    14 15 2
    RGRGRBGGBRBRGG
    1 2
    2 3
    2 4
    5 2
    7 4
    4 6
    10 6
    11 7
    10 13
    11 13
    8 5
    8 12
    8 9
    14 9
    12 14
    
    예상 출력
    833333340