#include #include class Node { public: int num; char s; std::vector node_nums; Node(int num, char s) : num(num), s(s) {} int append(int n) { node_nums.push_back(n); return n; } }; std::vector nodes; void search_pdca(Node& node, int count, int& n) { std::string pdca = "PDCA"; if (node.s == pdca[count]) { if (count == 3) { n += 1; return; } for (int i = 0; i < node.node_nums.size(); i++) { search_pdca(nodes[node.node_nums[i]], count + 1, n); } } } int main() { std::string pdca = "PDCA"; int n, m, q, count; count = 0; std::string s; std::cin >> n >> m; std::cin >> s; for (int i = 0; i < n; i++) { nodes.push_back(Node(i, s[i])); } int u, v; for (int i = 0; i < m; i++) { std::cin >> u >> v; u -= 1; v -= 1; std::string m = {nodes[u].s, nodes[v].s}; if (m == "PD" || m == "DC" || m == "CA") { nodes[u].append(v); nodes[v].append(u); } } for (int i = 0; i < nodes.size(); i++) { search_pdca(nodes[i], 0, count); } std::cout << count % 1000000007 << std::endl; };