/* -*- coding: utf-8 -*- * * 762.cc: No.762 PDCAパス - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MOD = 1000000007; /* typedef */ typedef long long ll; typedef vector vi; typedef queue qi; /* global variables */ char s[MAX_N + 4]; int vids[256], vs[MAX_N], ds[MAX_N]; vi nbrs[MAX_N]; bool used[MAX_N]; qi qs[4]; /* subroutines */ /* main */ int main() { vids['P'] = 0, vids['D'] = 1, vids['C'] = 2, vids['A'] = 3; int n, m; scanf("%d%d%s", &n, &m, s); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; nbrs[u].push_back(v); nbrs[v].push_back(u); } for (int i = 0; i < n; i++) if ((vs[i] = vids[s[i]]) == 0) ds[i] = 1, used[i] = true, qs[0].push(i); for (int i = 0; i < 3; i++) { qi &q = qs[i]; while (! q.empty()) { int u = q.front(); q.pop(); vi &nbru = nbrs[u]; for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) { int &v = *vit; if (vs[v] == i + 1) { ds[v] = (ds[v] + ds[u]) % MOD; if (! used[v]) { used[v] = true; qs[i + 1].push(v); } } } } } int sum = 0; while (! qs[3].empty()) { int u = qs[3].front(); qs[3].pop(); sum = (sum + ds[u]) % MOD; } printf("%d\n", sum); return 0; }