#include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(i=0; i=a; --i) #define in(a) cin >> a #define out(a,b) cout << a << b #define print_vec(v) for(auto it=v.begin();it!=v.end();++it)cout<<*it <<" ";cout<>v[i] #define v2din(v) for(int i=0;i>v[i][j];} #define vpairin(v) for(int i=0;i>a>>b;v[i]=make_pair(a,b);} using namespace std; using lint = long long; typedef struct { lint hi; // previously: not scored, scored pair sc; // next, score vector > gt; } gr; int main(void){ lint i, j; lint k, cnt=0, x, y; lint p, q, n, m; string s; in(n);in(m); vector vc(n); vector vz(n); rep(i,n){ lint a; in(a); vc[i].hi=a; vz[i].hi=a; vc[i].sc.first=-1; vz[i].sc.first=-1; vc[i].sc.second=-1; vz[i].sc.second=-1; } rep(i,m){ in(x);in(y); x--;y--; // if(vc[y].hi-vc[x].hi>0) vc[x].gt.push_back(make_pair(y, vc[y].hi-vc[x].hi)); // else vc[x].gt.push_back(make_pair(y, 0)); // if(vz[x].hi-vz[y].hi>0) vz[y].gt.push_back(make_pair(x, vz[x].hi-vz[y].hi)); // else vz[y].gt.push_back(make_pair(x, 0)); // vz[y].gt.push_back(x); vc[x].gt.push_back(make_pair(y, vc[y].hi-vc[x].hi)); vz[y].gt.push_back(make_pair(x, vz[x].hi-vz[y].hi)); } vector qc={0}; vc[0].sc.first=0; while(!qc.empty()){ lint cc=qc.back();qc.pop_back(); // cout << cc << endl; rep(i,vc[cc].gt.size()){ if(vc[cc].gt[i].second<=0){ if(vc[vc[cc].gt[i].first].sc.first-1&&vc[vc[cc].gt[i].first].sc.second qz={n-1}; vz[n-1].sc.first=0; // lint cz=n-1; while(!qz.empty()){ lint cz=qz.back();qz.pop_back(); rep(i,vz[cz].gt.size()){ if(vz[cz].gt[i].second<=0){ if(vz[vz[cz].gt[i].first].sc.first-1&&vz[vz[cz].gt[i].first].sc.second