#include <bits/stdc++.h>
using namespace std;
struct node {
  long long val, lazy;
  node() { val = lazy = 0; }
};
node tre[3 * 400005];
void propagete(long long n, long long l, long long r) {
  tre[n].val += tre[n].lazy;
  if (l != r) {
    tre[2 * n].lazy += tre[n].lazy;
    tre[2 * n + 1].lazy += tre[n].lazy;
  }
  tre[n].lazy = 0;
}
long long combine(long long a, long long b) { return min(a, b); }
void init(long long n, long long l, long long r) {
  if (l == r) {
    tre[n].val = 1LL << 50;
    return;
  }
  long long mid = (l + r) / 2;
  init(2 * n, l, mid);
  init(2 * n + 1, mid + 1, r);
  tre[n].val = combine(tre[2 * n].val, tre[2 * n + 1].val);
}
void update(long long n, long long l, long long r, long long i, long long j,
            long long val) {
  if (i > j) return;
  propagete(n, l, r);
  if (l > j || r < i) return;
  if (i <= l && j >= r) {
    tre[n].lazy += val;
    propagete(n, l, r);
    return;
  }
  long long mid = (l + r) / 2;
  update(2 * n, l, mid, i, j, val);
  update(2 * n + 1, mid + 1, r, i, j, val);
  tre[n].val = combine(tre[2 * n].val, tre[2 * n + 1].val);
}
long long query(long long n, long long l, long long r, long long i,
                long long j) {
  propagete(n, l, r);
  if (i > j) return (1LL << 55);
  if (l > j || r < i) return (1LL << 55);
  if (i <= l && j >= r) {
    return tre[n].val;
  }
  long long mid = (l + r) / 2;
  return combine(query(2 * n, l, mid, i, j),
                 query(2 * n + 1, mid + 1, r, i, j));
}
long long st[400005], idx[400005], ed[400005];
long long T;
vector<long long> adj[400005], upre[400005], niche[400005];
long long arr[400005];
long long dp[400005];
void dfs(long long n, long long par = 0) {
  st[n] = T;
  for (auto &cv : niche[n]) {
    idx[cv] = T++;
  }
  for (auto &cv : adj[n]) {
    if (cv == par) continue;
    dfs(cv, n);
  }
  ed[n] = T;
}
long long sol(long long n, long long par) {
  long long chlds = 0;
  for (auto &cv : adj[n]) {
    if (cv == par) continue;
    chlds += sol(cv, n);
    chlds = min(chlds, 1LL << 55);
  }
  if (n == 1) return dp[n] = chlds;
  for (auto &cv : upre[n]) update(1, 0, T, idx[cv], idx[cv], 1LL << 55);
  for (auto &cv : adj[n]) {
    if (cv == par) continue;
    update(1, 0, T, st[cv], ed[cv] - 1, chlds - dp[cv]);
  }
  for (auto &cv : niche[n]) {
    update(1, 0, T, idx[cv], idx[cv],
           chlds + arr[cv] - query(1, 0, T, idx[cv], idx[cv]));
  }
  return dp[n] = query(1, 0, T, st[n], ed[n] - 1);
}
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y >> arr[i];
    upre[y].push_back(i);
    niche[x].push_back(i);
  }
  dfs(1);
  init(1, 0, T);
  long long ans = sol(1, 0);
  if (ans >= 1000000000000000) ans = -1;
  cout << ans << endl;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
