#include struct dsu { dsu() {} explicit dsu(int n) : _cc(n), dat(n, -1) {} int size() const { return std::size(dat); } int root(int v) { assert(0 <= v), assert(v < size()); return dat[v] < 0 ? v : dat[v] = root(dat[v]); } std::pair unite(int u, int v) { assert(0 <= u), assert(u < size()); assert(0 <= v), assert(v < size()); u = root(u), v = root(v); if (u == v) return {u, -1}; --_cc; if (-dat[u] < -dat[v]) std::swap(u, v); dat[u] += dat[v]; dat[v] = u; return {u, v}; } bool same(int u, int v) { assert(0 <= u), assert(u < size()); assert(0 <= v), assert(v < size()); return root(u) == root(v); } int size(int v) { assert(0 <= v), assert(v < size()); return -dat[root(v)]; } int cc() const { return _cc; } private: int _cc; std::vector dat; }; #pragma region my_template struct Rep { struct I { int i; void operator++() { ++i; } int operator*() const { return i; } bool operator!=(I o) const { return i < *o; } }; const int l, r; Rep(int _l, int _r) : l(_l), r(_r) {} Rep(int n) : Rep(0, n) {} I begin() const { return {l}; } I end() const { return {r}; } }; struct Per { struct I { int i; void operator++() { --i; } int operator*() const { return i; } bool operator!=(I o) const { return i > *o; } }; const int l, r; Per(int _l, int _r) : l(_l), r(_r) {} Per(int n) : Per(0, n) {} I begin() const { return {r - 1}; } I end() const { return {l - 1}; } }; template struct Fix : private F { Fix(F f) : F(f) {} template decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, std::forward(args)...); } }; template T scan() { T res; std::cin >> res; return res; } template bool chmin(T& a, U&& b) { return b < a ? a = std::forward(b), true : false; } template bool chmax(T& a, U&& b) { return a < b ? a = std::forward(b), true : false; } #ifndef LOCAL #define DUMP(...) void(0) template constexpr int OjLocal = OnlineJudge; #endif using namespace std; #define ALL(c) begin(c), end(c) #pragma endregion int main() { cin.tie(nullptr)->sync_with_stdio(false); cout << fixed << setprecision(20); int n = scan(), m = scan(); vector a(n + 1); for (int i : Rep(n)) { int b = scan(); if (i & 1) b = -b; a[i] += b; a[i + 1] -= b; } dsu d(n + 1); while (m--) { int l = scan() - 1, r = scan(); tie(l, r) = d.unite(l, r); if (r != -1) a[l] += a[r]; } for (int i : Rep(n + 1)) if (d.root(i) == i) { if (a[i]) { cout << "NO\n"; exit(0); } } cout << "YES\n"; }