1 #include<bits/stdc++.h>
2 using namespace std;
3 const int N=1e6+5;
4 int next[2*N],head[N],to[N*2],d[N],add[N],fa[N],sum[N],top[N],size[N],son[N];
5 int n;
6 int m,q,w,ans,p,tot;
7 int read()
8 {
9 int f=1;char ch;
10 while((ch=getchar())<'0'||ch>'9')
11 if(ch=='-')f=-1;
12 int res=ch-'0';
13 while((ch=getchar())>='0'&&ch<='9')
14 res=res*10+ch-'0';
15 return res*f;
16 }
17 void write(int x)
18 {
19 if(x<0)
20 {
21 putchar('-');
22 x=-x;
23 }
24 if(x>9)write(x/10);
25 putchar(x%10+'0');
26 }
27 void ADD(int x,int y)
28 {
29 next[++tot]=head[x];
30 head[x]=tot;
31 to[tot]=y;
32 }
33 int lca(int x,int y)
34 {
35 while(top[x]!=top[y])
36 d[top[x]]>d[top[y]]?x=fa[top[x]]:y=fa[top[y]];
37 return d[x]<d[y]?x:y;
38 }
39 void dfs1(int s)
40 {
41 size[s]=1;
42 for(int i=head[s],t;i,t=to[i];i=next[i])
43 {
44 if(t==fa[s])continue;
45 fa[t]=s;d[t]=d[s]+1;
46 dfs1(t);
47 if(size[t]>size[son[s]])son[s]=t;
48 size[s]+=size[t];
49
50 }
51 }
52 void dfs2(int s)
53 {
54 if(son[s])
55 {
56 top[son[s]]=top[s];
57 dfs2(son[s]);
58 }
59 for(int i=head[s],t;i,t=to[i];i=next[i])
60 {
61 if(!top[t])
62 {
63 top[t]=t;
64 dfs2(t);
65 }
66 }
67 }
68 void dfs3(int s)
69 {
70 sum[s]=add[s];
71 for(int i=head[s],t;i,t=to[i];i=next[i])
72 {
73 if(t!=fa[s])
74 {
75 dfs3(t);
76 sum[s]+=sum[t];
77 }
78 }
79 }
80 int main()
81 {
82 n=read();m=read();
83 for(int i=1;i<n;i++)
84 {
85 int x,y;
86 x=read();y=read();
87 ADD(x,y);
88 ADD(y,x);
89 }
90 top[1]=d[1]=1;
91 dfs1(1);
92
93 dfs2(1);
94 for(int i=1;i<=m;i++)
95 {
96 int x,y;
97 x=read();y=read();
98 add[x]++;add[y]++;add[lca(x,y)]-=2;
99 }
100 dfs3(1);
101 for(int i=2;i<=n;i++)
102 {
103 if(sum[i]<2)sum[i]?ans++:ans+=m;
104 }
105 write(ans);
106 return 0;
107 }