use std::collections::HashSet; use proconio::input; fn main() { input! { n:usize, m:usize, uv:[(usize,usize);m], mut v:[usize;3], } let mut g = vec![vec![]; n]; for &(u, v) in uv.iter() { g[u].push(v); g[v].push(u); } let mut loops = vec![]; for i in 0..n { dfs(i, n, &mut vec![], &g, &mut loops); } let mut set_loops = HashSet::new(); for mut lop in loops { lop.sort(); set_loops.insert(lop); } v.sort(); let ans = set_loops.iter().any(|lop| lop != &v); println!("{}", if ans { "Yes" } else { "No" }); } fn dfs( crr: usize, prv: usize, path: &mut Vec, g: &Vec>, loops: &mut Vec>, ) { path.push(crr); for &nxt in g[crr].iter() { if path[0] == nxt && nxt != prv { loops.push(path.clone()); } if !path.contains(&nxt) { dfs(nxt, crr, path, g, loops); } } path.pop(); }