問題一覧 > 通常問題

No.762 PDCA Path

レベル : / AI推定難易度 : 1000 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 256 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 159
作問者 : mai / テスター : matsu7874
お気に入りにしたユーザー ProblemId : 1986 / 自分の提出
問題文最終更新日: 2025-02-10 00:15:56
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2018 (順位表) の他の問題:

Problem Statement

You are given a graph consisting of $N$ vertices and $M$ undirected edges.

The $i$-th vertex has one of the characters P,D,C,A written on it.
The $j$-th edge connects the $u_j$-th vertex and the $v_j$-th vertex.


A way of going from one vertex to another in which the start and end vertices are different and no vertex is visited more than once is called a path.
A path of length 3 is a path consisting of 3 edges and 4 vertices.

A path of length 3 is called a PDCA path if, when its vertices are traversed from one end to the other, they can be read as PDCA.


Among the paths of length 3 in the graph, how many PDCA paths are there? Find the count modulo $10^9+7$.

Input

N M
S
u_1 v_1
...
u_M v_M

$2 \le N \le 10^5$
$0 \le M \le 10^5$
$|S| = N$
$1 \le u_i \lt v_i \le N$
The given graph does not contain multiple edges or self-loops.
Each character of the string $S$ is one of P,D,C,A.
The $i$-th character of $S$ indicates the character written on vertex number $i$.

Output

Output the number of PDCA paths modulo 1000000007.

Print a newline at the end.

Sample

Sample 1
Input
7 11
PAAPCDD
1 3
1 5
1 6
2 5
2 6
3 5
5 6
4 5
5 7
4 7
2 7
Output
4

There are 4 such paths: 1,6,5,2, 1,6,5,3, 4,7,5,2, 4,7,5,3.

Sample 2
Input
6 3
ACPPPD
1 2
3 4
4 5
Output
0

The graph is not necessarily connected, and there may be no PDCA paths.

Sample 3
Input
11 11
AAACCCDDPPP
1 4
1 5
2 5
4 7
5 7
7 9
7 10
2 4
3 6
6 8
8 11
Output
9

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。