#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using P = pair; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m; cin >> n >> m; vector> g(n); for(int i = 0; i < m; i++){ int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } vector a(n), b(n), c(n); for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; auto ok = [&](int x) -> bool{ if(x <= a[0]+b[0]+c[0]) return false; priority_queue, greater> que; ll sum = 0; auto push = [&](int x){ sum += x; que.push(x); }; auto pop = [&](){ int x = que.top(); sum -= x; que.pop(); }; push(1); push(1); push(x-2); push(a[0]); push(b[0]); push(c[0]); while(que.size() > 3) { pop(); } vector seen(n); seen[0] = true; priority_queue, greater

> que_p; for(int to: g[0]){ int sum = a[to]+b[to]+c[to]; que_p.push(P(sum, to)); seen[to] = true; } while(!que_p.empty()){ auto [s, v] = que_p.top(); que_p.pop(); if(s >= sum) return false; if(v == n-1) return true; push(a[v]); push(b[v]); push(c[v]); while(que.size() > 3) pop(); for(int to: g[v]){ if(seen[to]) continue; int sum = a[to]+b[to]+c[to]; que_p.push(P(sum, to)); seen[to] = true; } } }; int l = 3, r = (3e8)+1; while(r-l > 1){ int x = (l+r)/2; if(ok(x)) r = x; else l = x; } cout << 1 << ' ' << 1 << ' ' << r-2 << endl; }