package main import ( "bufio" "fmt" "os" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 2 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) m := getNextInt(scanner) s := getNextString(scanner) g := newGraph(n) for i := 0; i < n; i++ { g.v[i] = new(vertex) g.v[i].ch = s[i] if s[i] == 'P' { g.v[i].into = 1 } } for i := 0; i < m; i++ { u := getNextInt(scanner) - 1 v := getNextInt(scanner) - 1 g.appendEdge(u, v, i) g.appendEdge(v, u, i) } moves := [3][2]byte{ [2]byte{'P', 'D'}, [2]byte{'D', 'C'}, [2]byte{'C', 'A'}, } for c := 0; c < 3; c++ { for i := 0; i < n; i++ { if g.v[i].ch == moves[c][0] { for _, e := range g.e[i] { if g.v[e.to].ch == moves[c][1] { g.v[e.to].into.addAs(g.v[i].into) } } } } } var ans mint for i := 0; i < n; i++ { if g.v[i].ch == 'A' { ans.addAs(g.v[i].into) } } fmt.Fprintln(writer, ans) } type graph struct { v []*vertex e [][]*edge } func newGraph(n int) *graph { return &graph{ v: make([]*vertex, n), e: make([][]*edge, n), } } func (g *graph) appendEdge(from, to, id int) { g.e[from] = append(g.e[from], &edge{ to: to, id: id, }) } type vertex struct { ch byte into mint } type edge struct { to, id int } type mint int func (mt mint) mod() mint { m := mint(1e9 + 7) mt %= m if mt < 0 { return mt + m } return mt } func (mt mint) inv() mint { var m, y mint m.subAs(2) dbl := mt y = 1 for i := 0; i < 31; i++ { if m%2 == 1 { y.mulAs(dbl) } m >>= 1 dbl.mulAs(dbl) } return y } func (mt mint) add(x mint) mint { return (mt + x).mod() } func (mt mint) sub(x mint) mint { return (mt - x).mod() } func (mt mint) mul(x mint) mint { return (mt * x).mod() } func (mt mint) div(x mint) mint { return mt.mul(x.inv()) } func (mt *mint) addAs(x mint) *mint { *mt = mt.add(x) return mt } func (mt *mint) subAs(x mint) *mint { *mt = mt.sub(x) return mt } func (mt *mint) mulAs(x mint) *mint { *mt = mt.mul(x) return mt } func (mt *mint) divAs(x mint) *mint { *mt = mt.div(x) return mt }