1 #include<iostream>
2 #include<cstdio>
3 #include<cstdlib>
4 #include<cstring>
5 #include<algorithm>
6 using namespace std;
7 const int N=10050;
8 typedef long long ll;
9
10
11 struct Edge{
12 int to,next;
13 ll val;
14 }edge[N];
15 int n,m,x,y,first[N],tot;
16 int S[N],E[N],Tim;
17 ll sum,dis[N],z;
18
19 template <class T>
20 inline void read(T &s){
21 int flag=1;s=0;char ch=getchar();
22 while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)flag=-1;ch=getchar();}
23 while(ch>=‘0‘ && ch<=‘9‘){s=s*10+ch-‘0‘;ch=getchar();}
24 s*=flag;
25 }
26 void dfs(int x){
27 S[x]=++Tim;
28 for(int i=first[x];i;i=edge[i].next){
29 dis[edge[i].to]=dis[x]+edge[i].val;
30 dfs(edge[i].to);
31 }
32 E[x]=++Tim;
33 }
34 inline void Add_edge(int a,int b,int c){
35 edge[++tot].to=b;edge[tot].val=c;edge[tot].next=first[a];first[a]=tot;
36 }
37 int main(){
38 read(n);read(m);
39 for(int i=1;i<n;++i){
40 read(x);read(y);read(z);
41 Add_edge(x,y,z);
42 }
43 dfs(1);
44 int ans=0;
45 for(int i=1;i<=m;++i){
46 read(x);read(y);
47 if(S[x]<S[y] && E[x]>E[y]){
48 ++ans;sum+=dis[y]-dis[x];
49 }
50 }
51 printf("%d\n%lld\n",ans,sum);
52 return 0;
53 }