#include using namespace std; int main() { int N,M; cin >> N >> M; vector>road(N); for(int i = 0; i < M; i++) { int U,V; cin >> U >> V; U--; V--; road[U].push_back(V); road[V].push_back(U); } vector>C(N,vector(3)); for(int i = 0; i < N; i++) { cin >> C[i][0] >> C[i][1] >> C[i][2]; sort(C[i].rbegin(),C[i].rend()); } int l = C[0][0]+C[0][1]+C[0][2]-1,r = 1001001001; while (l+1 < r) { int mid = (l+r)/2; vectordist(N,-1); dist[0] = 0; int a = mid-2,b = C[0][0],c = 1; queueque; que.push(0); priority_queue,vector>,greater>>que2; while (!que.empty()) { int x = que.front(); que.pop(); for(int i:road[x]) { if(dist[i] == -1) { que2.push({C[i][0]+C[i][1]+C[i][2],i}); } } while (!que2.empty()) { pair x = que2.top(); if(x.first < a+b+c) { if(c == 1) { c = C[0][1]; } que2.pop(); dist[x.second] = 0; que.push(x.second); for(int i = 0; i < 3; i++) { if(c < C[x.second][i]) { c = C[x.second][i]; } else if(b < C[x.second][i]) { b = C[x.second][i]; } else if(a < C[x.second][i]) { a = C[x.second][i]; } } } else { break; } } } if(dist[N-1] != -1) { r = mid; } else { l = mid; } } cout << r-2 << " " << 1 << " " << 1 << endl; }