use proconio::input; use proconio::marker::Usize1; fn main() { input! { n : usize, m : usize, k : usize, x : [Usize1; k], edges : [(Usize1, Usize1); m] } let mut g = vec![vec![]; n]; for (u, v) in edges { g[u].push(v); g[v].push(u); } let mut dp = vec![vec![false; n]; 1 << k]; for (i, &x) in x.iter().enumerate() { dp[1 << i][x] = true; } for (i, &x) in x.iter().enumerate() { for s in 0..1 << k { dp[s | (1 << i)][x] |= dp[s][x]; } } // for i in 0..n { eprintln!("{} => {:?}", i, g[i]) } let mut ok = false; for aa in 0..n { let mut next = vec![vec![false; n]; 1 << k]; for s in 0..1 << k { let mut t = s; for i in 0..n { for &u in g[i].iter() { next[s][u] |= dp[s][i]; } } while t >= 0 { for i in 0..n { for &u in g[i].iter() { next[s][u] |= dp[s ^ t][i] && next[t][u]; } } if t == 0 { break; } t = (t - 1) & s; } } dp = next; } ok |= dp[(1 << k) - 1].iter().any(|&a| a); println!("{}", if ok { "Yes" } else { "No" }) }