use proconio::marker::Usize1; use proconio::*; fn main() { input! { n: usize, m: usize, k: usize, x: [Usize1; k], edges: [(Usize1, Usize1); m], } let mut graph = vec![vec![]; n]; for (a, b) in edges { graph[a].push(b); graph[b].push(a); } let mut v = vec![]; for i in 0..k { v.push(dfs(x[i], &mut vec![x[i]], &graph, &mut vec![(x[i], 1)])); } for i in v[0].iter() { let mut res = true; for j in 1..k { if !v[j].contains(&i) { res = false; break; } } if res { println!("{}", "Yes"); return; } } println!("{}", "No"); } fn dfs( v: usize, seen: &mut Vec, graph: &Vec>, ret: &mut Vec<(usize, usize)>, ) -> Vec<(usize, usize)> { for &i in &graph[v] { if seen.contains(&i) { continue; } seen.push(i); ret.push((i, seen.len())); dfs(i, seen, graph, ret); seen.pop(); } ret.clone() }