#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(ll n, ll m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(ll n, ll m, ll k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void prll_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(ll 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; ll n, m; cin >> n >> m; vector> g(n); for(ll i = 0; i < m; i++){ ll 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(ll i = 0; i < n; i++) { cin >> a[i] >> b[i] >> c[i]; vector v = {a[i], b[i], c[i]}; sort(v.begin(), v.end()); a[i] = v[0]; b[i] = v[1]; c[i] = v[2]; } auto ok = [&](ll x) -> bool{ if(x <= a[0]+b[0]+c[0]) return false; priority_queue, greater> que; ll sum = 0; auto push = [&](ll x){ sum += x; que.push(x); }; auto pop = [&](){ ll x = que.top(); sum -= x; que.pop(); }; push(1); push(1); push(x-2); push(c[0]); pop(); vector seen(n); seen[0] = true; priority_queue, greater

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