#include #pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll ILL=1167167167167167167; const int INF=2100000000; const ll mod=998244353; #define rep(i,a) for (ll i=0;i using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,const T &b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";} template void vec_out(vector &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout< &p){ int ans=0; for(auto x:p) ans+=x; return ans; } vector f(vector p,vector q){ for(auto x:q) p.push_back(x); Sore(p); p.resize(3); return p; } void solve(); // oddloop int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t=1; //cin>>t; rep(i,t) solve(); } void solve(){ int N,M; cin>>N>>M; vector> G(N); rep(i,M){ int u,v; cin>>u>>v; u--,v--; G[u].push_back(v); G[v].push_back(u); } vector> A(N,vector(3)); rep(i,N) rep(j,3) cin>>A[i][j]; So(A[0]); int l=S(A[0])-2,r=INF/2; while(r-l>1){ int med=(r+l)/2; vector have={1,1,med}; vector seen(N); seen[0]=1; _pq> pq; pq.push({0,0}); int J=1; while(!pq.empty()){ if(S(have)<=pq.top().first) break; int ind,v; tie(v,ind)=pq.top(); if(J==-1) have=f(have,A[ind]); else if(J==0){ have=f({1,1,med},A[0]); have=f(have,A[ind]); J=-1; }else{ have[0]=A[0][2]; J=0; } pq.pop(); seen[ind]=2; for(auto x:G[ind]){ if(seen[x]==0) pq.push({S(A[x]),x}),seen[x]=1; } } if(seen[N-1]==2) r=med; else l=med; } cout<<"1 1 "<