use proconio::{ input, marker::{Chars, Usize1}, }; fn main() { input! { n: usize, m: usize, s: Chars, ab: [(Usize1, Usize1); m], } let mut graph = vec![vec![]; n]; for (a, b) in ab { graph[a].push(b); graph[b].push(a); } let question_count = s.iter().filter(|&&x| x == '?').count(); let mut ans = 0; for start in 0..n { if s[start] == 'a' || s[start] == '?' { dfs( start, 0, &mut ans, question_count, &mut vec![start], &s, &graph, ); } } println!("{}", ans); } fn dfs( pos: usize, count: usize, ans: &mut usize, question_count: usize, route: &mut Vec, s: &Vec, graph: &Vec>, ) { let target = match count { 0 => 'o', 1 => 'i', _ => unreachable!(), }; for &next in &graph[pos] { if s[next] != target && s[next] != '?' { continue; } if s[next] == '?' && route.contains(&next) { continue; } if count + 1 == 2 { let rest_question_count = question_count - route.iter().filter(|&&i| s[i] == '?').count(); *ans += pow(26, rest_question_count); *ans += 1; *ans %= 998244353; continue; } route.push(next); dfs(next, count + 1, ans, question_count, route, s, graph); route.pop(); } } fn pow(mut n: usize, mut m: usize) -> usize { let mut r = 1; while m > 0 { if m & 1 == 1 { r *= n; r %= 998244353; } n *= n; n %= 998244353; m >>= 1; } r }