#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int M = 100005;
int n,m,x,y,tot;
long long f[M][4];
struct node{
int link;
int next;
int son;
}t[M];
void add(int x,int y){
t[++tot].next = t[x].link;
t[x].link = tot;
t[tot].son = y;
}
void dfs(int x,int fa){
for(int i=1;i<=3;i++){
if(f[x][i]){
for(int j=1;j<i;j++)
f[x][j]=0;
break;
}
f[x][i]=1;
}
for(int i=t[x].link;i>0;i=t[i].next)
if(t[i].son != fa){
dfs(t[i].son,x);
f[x][1] = f[x][1]*((f[t[i].son][2]+f[t[i].son][3])%mod)%mod;
f[x][2] = f[x][2]*((f[t[i].son][1]+f[t[i].son][3])%mod)%mod;
f[x][3] = f[x][3]*((f[t[i].son][2]+f[t[i].son][1])%mod)%mod;
}
}
int main(){
cin >> n >> m;
for (int i=1;i<n;i++){
cin >> x >> y;
add(x,y);
add(y,x);
}
for (int i=1;i<=m;i++){
cin >> x >> y;
f[x][y] = 1;
}
dfs(1,0);
cout << (f[1][1]+f[1][2]+f[1][3])%mod;
return 0;
}
救救孩子吧,调了一晚上了
5555~~~~