#include typedef struct Edge { struct Edge *next; int v; } edge; typedef struct { int key, id; } data; typedef struct { data obj[100001]; int size; } min_heap; void push(min_heap* h, data x) { int i = ++(h->size), j = i >> 1; data tmp; h->obj[i] = x; while (j > 0) { if (h->obj[i].key < h->obj[j].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j >>= 1; } else break; } } data pop(min_heap* h) { int i = 1, j = 2; data output = h->obj[1], tmp; h->obj[1] = h->obj[(h->size)--]; while (j <= h->size) { if (j < h->size && h->obj[j^1].key < h->obj[j].key) j ^= 1; if (h->obj[j].key < h->obj[i].key) { tmp = h->obj[j]; h->obj[j] = h->obj[i]; h->obj[i] = tmp; i = j; j <<= 1; } else break; } return output; } int main() { int i, N, M, u, w, A[100001], B[100001], C[100001]; edge *adj[100001] = {}, e[200001], *p; scanf("%d %d", &N, &M); for (i = 0; i < M; i++) { scanf("%d %d", &u, &w); e[i*2].v = w; e[i*2+1].v = u; e[i*2].next = adj[u]; e[i*2+1].next = adj[w]; adj[u] = &(e[i*2]); adj[w] = &(e[i*2+1]); } for (u = 1; u <= N; u++) { scanf("%d %d %d", &(A[u]), &(B[u]), &(C[u])); if (A[u] > B[u]) { A[u] ^= B[u]; B[u] ^= A[u]; A[u] ^= B[u]; } if (B[u] > C[u]) { B[u] ^= C[u]; C[u] ^= B[u]; B[u] ^= C[u]; } if (A[u] > B[u]) { A[u] ^= B[u]; B[u] ^= A[u]; A[u] ^= B[u]; } } int l = 1, r = 1 << 29, m, x, y, z, flag[100001], in[100001]; min_heap h; data d; while (l < r) { m = (l + r) / 2; x = 1; y = 1; z = m; for (u = 1; u <= N; u++) { flag[u] = 0; in[u] = 0; } h.size = 0; d.key = A[1] + B[1] + C[1]; d.id = 1; push(&h, d); in[1] = 1; while (h.size > 0) { if (h.obj[1].id == N && x + y + z > h.obj[1].key) break; d = pop(&h); if (x + y + z <= d.key) { h.size = 0; break; } u = d.id; in[u] = 0; if (flag[u] == 0) { if (C[u] > x) { x = C[u]; if (x > y) { x ^= y; y ^= x; x ^= y; } if (y > z) { y ^= z; z ^= y; y ^= z; } } } else if (flag[u] == 1) { if (B[u] > x) { x = B[u]; if (x > y) { x ^= y; y ^= x; x ^= y; } if (y > z) { y ^= z; z ^= y; y ^= z; } } } else { if (A[u] > x) { x = A[u]; if (x > y) { x ^= y; y ^= x; x ^= y; } if (y > z) { y ^= z; z ^= y; y ^= z; } } } flag[u]++; if (flag[u] <= 2 && (u != 1 || flag[u] != 1)) { d.key = A[u] + B[u] + C[u]; d.id = u; push(&h, d); in[u] = 1; } for (p = adj[u]; p != NULL; p = p->next) { w = p->v; if (flag[w] <= 2 && in[w] == 0) { d.key = A[w] + B[w] + C[w]; d.id = w; push(&h, d); in[w] = 1; } } } if (h.size > 0) r = m; else l = m + 1; } printf("1 1 %d\n", l); fflush(stdout); return 0; }