use proconio::marker::Usize1; use proconio::*; use std::collections::HashSet; 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 { let mut seen = HashSet::new(); seen.insert(x[i]); v.push(dfs(x[i], &mut seen, &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 HashSet, graph: &Vec>, ret: &mut Vec<(usize, usize)>, ) -> Vec<(usize, usize)> { for &i in &graph[v] { if seen.contains(&i) { continue; } seen.insert(i); ret.push((i, seen.len())); dfs(i, seen, graph, ret); seen.remove(&i); } ret.clone() }