using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int pointCount = inpt[0]; int pathCount = inpt[1]; int[] pointList = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); Dictionary> path = new Dictionary>(); for (int i = 0; i < pathCount; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a) - 1).ToArray(); if(!path.ContainsKey(inpt[0])) { path.Add(inpt[0], new Dictionary()); } path[inpt[0]].Add(inpt[1], true); if(!path.ContainsKey(inpt[1])) { path.Add(inpt[1], new Dictionary()); } path[inpt[1]].Add(inpt[0], true); } bool hasKadomatu = false; for (int i = 0; i < pointCount; i++) { int num = pointList[i]; if(!path.ContainsKey(i)) { continue; } if(path[i].Count(a=>pointList[a.Key]=2) { hasKadomatu = true; break; } else if(path[i].Count(a=>pointList[a.Key]>num)>=2) { hasKadomatu = true; break; } } Console.WriteLine(hasKadomatu?"YES":"NO"); } public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 3 2 1 3 2 1 2 2 3 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }