// warm heart, wagging tail,and a smile just for you! // ███████████ // ███╬╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬████╬╬╬╬╬╬███ // ███████████ ██╬╬╬╬╬████╬╬████╬╬╬╬╬██ // █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██ // ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██ // ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██ // ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████ // █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██ // ██████████████ ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████ // ███████ █████ ███████████████████ // #include "bits/stdc++.h" using namespace std; #define INF (1<<30) #define LINF (1LL<<60) #define fs first #define sc second #define int long long #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i) #define REP(i,n) FOR(i,0,(n)) #define RREP(i,n) RFOR(i,0,(n)) #define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr) #define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr) #define range(i,a,b) ((a)<=(i) && (i)<(b)) #define debug(x) cout << #x << " = " << (x) << endl #define SP << " " << template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a P; typedef tuple T; typedef vector vec; typedef vector> mat; struct UnionFind { private: vector child,tree; vector> list; public: UnionFind(int v) { tree.resize(v); list.resize(v); REP(i,v) tree[i] = i, list[i].push_back(i); } int root(int i){ if(i == tree[i]){ REP(j,child.size()) tree[child[j]] = i; child.clear(); return i; } else{ child.push_back(i); return i = root(tree[i]); } } int size(int i){ return list[root(i)].size(); } vector nodes(int no){ return list[root(no)]; } bool unit(int x, int y){ x = root(x); y = root(y); if(x==y) return false; if(list[x].size() < list[y].size()) swap(x,y); for(int no:list[y]) list[x].emplace_back(no); tree[y] = x; return true; } bool isUnit(int x, int y){ return root(x) == root(y); } }; void ng(){ cout << "NO" << endl; exit(0); } const int N = 1e5+10; vector edge[N],color(N,0); bool isBip(int no){ if(!color[no]) color[no] = 1; bool flag = true; for(auto to:edge[no]){ if(color[no]==color[to]) flag = false; else if(!color[to]){ color[to] = -color[no]; if(!isBip(to)) flag = false; } } return flag; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); int n,m; cin >> n >> m; vector b(n+2); REP(i,n) cin >> b[i+1]; vector d(n+1); REP(i,n+1) d[i] = b[i]+b[i+1]; UnionFind uf(n+1); vector

op; REP(i,m){ int x,y; cin >> x >> y; if((y-x)%2) uf.unit(x-1,y); else op.emplace_back(x-1,y); } // 連結成分で座圧 map mp; REP(i,n+1) mp[uf.root(i)]++; int k = 0; // 連結成分数 ITR(itr,mp) itr->sc = k++; vector id(n+1),sum(k,0); // 座圧後のid, 連結成分内のdのsum REP(i,n+1){ id[i] = mp[uf.root(i)]; sum[id[i]] += d[i]; } vector flag(k,0); // 自己ループを含むか UnionFind uf2(k); REP(i,op.size()){ int x = id[op[i].fs], y = id[op[i].sc]; if(x==y) flag[x]++; else{ uf2.unit(x,y); edge[x].emplace_back(y); edge[y].emplace_back(x); } } map sum2; vector flag2(k,0), list[k]; REP(i,k){ sum2[uf2.root(i)] += sum[i]; flag2[uf2.root(i)] += flag[i]; list[uf2.root(i)].emplace_back(i); } REP(i,k){ if(uf2.root(i)!=i) continue; if(sum2[i]%2) ng(); // 総和を奇数にはできない if(flag2[i]) continue; // 自己ループ if(!isBip(i)) continue; // 奇閉路ある? int v = 0; for(int no:list[i]) v += sum[no]*color[no]; if(v) ng(); // 和が一致する? } cout << "YES" << endl; return 0; }