fn main() { proconio::input! { n: usize, m: usize, ab: [(usize, usize); m], } let graph = { let mut g = vec![vec![]; n]; for (a, b) in ab { g[a - 1].push(b - 1); g[b - 1].push(a - 1); } g }; let mut exists = vec![vec![false; n]; 6]; exists[0][0] = true; for len in 1..=5 { for ni in 0..n { if !exists[len - 1][ni] { continue; } for &nj in &graph[ni] { exists[len][nj] = true; } } } if exists[5][0] { println!("YES"); } else { println!("NO"); } }