using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int pointCount = inpt[0]; int connectCount = inpt[1]; for (int i = 0; i < connectCount; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); if (!con.ContainsKey(inpt[0])) { con.Add(inpt[0], new Dictionary()); } con[inpt[0]][inpt[1]] = true; if (!con.ContainsKey(inpt[1])) { con.Add(inpt[1], new Dictionary()); } con[inpt[1]][inpt[0]] = true; } bool ans = GetAns(1, 5); Console.WriteLine(ans ? "YES" : "NO"); } private bool GetAns(int pos, int remain) { if (!dic.ContainsKey(pos)) { dic.Add(pos, new Dictionary()); } if (dic[pos].ContainsKey(remain)) { return dic[pos][remain]; } if (remain == 0) { return pos == 1; } bool ans = false; if (con.ContainsKey(pos)) { foreach (int next in con[pos].Keys) { bool ret = this.GetAns(next, remain - 1); if (ret) { ans = true; break; } } } this.dic[pos].Add(remain, ans); return ans; } private Dictionary> con = new Dictionary>(); private Dictionary> dic = new Dictionary>(); public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 7 10 1 2 1 3 1 4 1 5 2 3 2 4 2 6 3 4 3 7 4 5 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }