fn dfs(cur: usize, paths: &Vec>, cnt: &mut usize, checked: &mut Vec) -> bool { if checked[cur] { return cur == 0 && *cnt == 5; } if *cnt > 5 { return false; } checked[cur] = true; *cnt += 1; for &v in paths[cur].iter() { if dfs(v, &paths, cnt, checked) { return true; } } checked[cur] = false; *cnt -= 1; false } fn main() { let mut nm = String::new(); std::io::stdin().read_line(&mut nm).ok(); let nm: Vec = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nm[0]; let m = nm[1]; let mut paths = vec![vec![]; n]; for _ in 0..m { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let a = temp[0]-1; let b = temp[1]-1; paths[a].push(b); paths[b].push(a); } let mut checked = vec![false; n]; let mut cnt = 0usize; if dfs(0, &paths, &mut cnt, &mut checked) { println!("YES"); } else { println!("NO"); } }