#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)
#define endl '\n'
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define mp make_pair
#define nd second
#define st first
#define type(x) __typeof(x.begin())
typedef pair < int ,int > pii;
typedef long long ll;
const long long linf = 1e15+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 1e6 + 5;
int n, m, x, y, z, c[N], start[N], finish[N], w[N], T;
vector< int > v[N], add[N], del[N];
ll dp[N], ST[N << 2], L[N << 2];
void dfs(int node, int root) {
start[node] = T + 1;
foreach(it, add[node]) w[*it] = ++T;
foreach(it, v[node]) {
if(*it != root) {
dfs(*it, node);
}
} finish[node] = T;
}
ll update(int k, int bas, int son, int x, ll D) {
if(bas > x || son < x) return ST[k];
if(bas == son) return ST[k] = D;
ST[k] = min(update(sol, bas, orta, x, D), update(sag, orta + 1, son, x, D)) + L[k];
if(ST[k] > linf) ST[k] = linf;
return ST[k];
}
ll update(int k, int bas, int son, int x, int y, ll D) {
if(bas > y || son < x) return ST[k];
if(x <= bas && son <= y) {
L[k] = min(linf, D + L[k]);
ST[k] = min(linf, D + ST[k]);
return ST[k];
}
ST[k] = min(update(sol, bas, orta, x, y, D), update(sag, orta + 1, son, x, y, D)) + L[k];
if(ST[k] > linf) ST[k] = linf;
return ST[k];
}
ll query(int k, int bas, int son, int x, int y) {
if(bas > y || son < x) return linf;
if(x <= bas && son <= y) return ST[k];
return min(linf, min(query(sol, bas, orta, x, y), query(sag, orta + 1, son, x, y)) + L[k]);
}
ll solve(int node, int root) {
ll all = 0;
foreach(it, v[node]) {
if(*it == root) continue;
all += solve(*it, node);
if(all != 2 * linf)
all = min(all, 2 * linf);
}
if(node == 1) return dp[node] = all;
foreach(it, add[node]) update(1, 1, m, w[*it], c[*it] + all);
foreach(it, del[node]) update(1, 1, m, w[*it], linf);
foreach(it, v[node])
if(*it != root)
update(1, 1, m, start[*it], finish[*it], all - dp[*it]);
dp[node] = query(1, 1, m, start[node], finish[node]);
return dp[node];
}
int main() {
scanf("%d %d", &n, &m);
FOR(i, 2, n) {
scanf("%d %d", &x, &y);
v[x].pb(y); v[y].pb(x);
}
FOR(i, 1, m) {
scanf("%d %d %d", &x, &y, &c[i]);
add[x].pb(i);
del[y].pb(i);
}
dfs(1, 0);
ll ans = solve(1, 0);
if(ans >= linf) ans = -1;
printf("%lld\n", ans);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBvcnRhIChiYXMgKyBzb24gPj4gMSkKI2RlZmluZSBzYWcgKGsgKyBrICsgMSkKI2RlZmluZSBzb2wgKGsgKyBrKQojZGVmaW5lIGVuZGwgJ1xuJwojZGVmaW5lIGZvcmVhY2goaSx4KSBmb3IodHlwZSh4KWk9eC5iZWdpbigpO2khPXguZW5kKCk7aSsrKQojZGVmaW5lIEZPUihpaSxhYSxiYikgZm9yKGludCBpaT1hYTtpaTw9YmI7aWkrKykKI2RlZmluZSBST0YoaWksYWEsYmIpIGZvcihpbnQgaWk9YWE7aWk+PWJiO2lpLS0pCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgbmQgc2Vjb25kCiNkZWZpbmUgc3QgZmlyc3QKI2RlZmluZSB0eXBlKHgpIF9fdHlwZW9mKHguYmVnaW4oKSkKCnR5cGVkZWYgcGFpciA8IGludCAsaW50ID4gcGlpOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7Cgpjb25zdCBsb25nIGxvbmcgbGluZiA9IDFlMTUrNTsKY29uc3QgaW50IG1vZCA9IChpbnQpIDFlOSArIDc7CmNvbnN0IGludCBsb2dOID0gMTc7CmNvbnN0IGludCBp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