#include <bits/stdc++.h>   using namespace std;   template <class T>   __inline__ __attribute__((always_inline)) T read() {     T x = 0, w = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) w = -w;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * w;   }   template <class T>   __inline__ __attribute__((always_inline)) T read(T& x) {     return x = read<T>();   }   const int N = 1e5 + 10;   struct edge {     int v;     long long w;   };   vector<edge> to[N];   long long dis[N];   void dfs(int u) {     for (const edge& e : to[u]) dis[e.v] = dis[u] + e.w, dfs(e.v);   }   int ch[N][2], fa[N];   long long tim[N], tag[N];   __inline__ __attribute__((always_inline)) bool nroot(int x) {     return ch[fa[x]][0] == x or ch[fa[x]][1] == x;   }   void push_down(int x) {     if (tag[x] != -1) {       if (ch[x][0]) tim[ch[x][0]] = tag[ch[x][0]] = tag[x];       if (ch[x][1]) tim[ch[x][1]] = tag[ch[x][1]] = tag[x];       tag[x] = -1;     }   }   void rotate(int x) {     int y = fa[x], z = fa[y], l = x == ch[y][1], r = l ^ 1;     if (nroot(y)) ch[z][y == ch[z][1]] = x;     fa[x] = z;     ch[y][l] = ch[x][r];     fa[ch[x][r]] = y;     ch[x][r] = y;     fa[y] = x;   }   void splay(int x) {     vector<int> stk = {x};     for (int i = x; nroot(i);) stk.push_back(i = fa[i]);     for (; stk.size(); stk.pop_back()) push_down(stk.back());     for (; nroot(x); rotate(x)) {       int y = fa[x], z = fa[y];       if (nroot(y)) rotate((x == ch[y][1]) != (y == ch[z][1]) ? x : y);     }   }   struct node {     long long l, r;   };   vector<node> buc;   priority_queue<long long, vector<long long>, greater<long long>> heap;   int main() {     int n = read<int>(), m = read<int>();     for (int i = 1; i < n; ++i) {       int u = read<int>(), v = read<int>();       to[u].push_back({v, read<long long>()});       ch[u][1] = v, fa[v] = u;     }     dfs(1);     for (int i = 1; i <= n; ++i) {       tim[i] = -dis[i];       tag[i] = -1;     }     while (m--) {       int s = read<int>();       long long t = read<long long>();       splay(s);       for (int x = fa[s], y = s; x; y = x, x = fa[x]) {         splay(x), ch[x][1] = y;         buc.push_back({tim[x] + dis[x] + 1, t + dis[x]});       }       splay(s);       if (ch[s][0]) tim[ch[s][0]] = tag[ch[s][0]] = t;     }     sort(buc.begin(), buc.end(),          [&](const node& a, const node& b) -> bool { return a.l < b.l; });     long long now = 1;     int cnt = 0;     for (int i = 0; i < (int)buc.size(); ++i) {       for (; buc[i].l > now and heap.size(); heap.pop()) {         long long r = heap.top();         if (now > r) {           for (int j = 0; j < i; ++j) cnt -= buc[j].r >= r;           for (; heap.size(); heap.pop()) cnt += heap.top() >= r;           printf( %lld %d n , r, cnt);           return 0;         }         now = now + 1;         ++cnt;       }       if (buc[i].l > now) now = buc[i].l;       heap.push(buc[i].r);     }     for (; heap.size(); heap.pop()) {       long long r = heap.top();       if (now > r) {         for (int i = 0; i < (int)buc.size(); ++i) cnt -= buc[i].r >= r;         for (; heap.size(); heap.pop()) cnt += heap.top() >= r;         printf( %lld %d n , r, cnt);         return 0;       }       now = now + 1, ++cnt;     }     printf( -1 %d n , cnt);     return 0;   }