/* -*- coding: utf-8 -*- * * 629.cc: No.629 グラフの中に眠る門松列 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000; /* typedef */ typedef vector vi; /* global variables */ int as[MAX_N]; vi nbrs[MAX_N]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &as[i]); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; nbrs[u].push_back(v); nbrs[v].push_back(u); } for (int i = 0; i < n; i++) { vi &nbr0 = nbrs[i]; for (vi::iterator vit0 = nbr0.begin(); vit0 != nbr0.end(); vit0++) { int &j = *vit0; if (as[i] == as[j]) continue; vi &nbr1 = nbrs[j]; for (vi::iterator vit1 = nbr1.begin(); vit1 != nbr1.end(); vit1++) { int &k = *vit1; if (as[i] != as[k] && ((as[j] < as[i] && as[j] < as[k]) || (as[j] > as[i] && as[j] > as[k]))) { puts("YES"); return 0; } } } } puts("NO"); return 0; }