#include <iostream>
#include <vector>
#include <stack>
using namespace std;
typedef long long ll;
struct Node {
int u, p;
ll s;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
ll k;
if (!(cin >> n >> k)) return 0;
vector<vector<int>> g(n + 1);
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<ll> val(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> val[i];
}
int ans = 0;
stack<Node> stk;
stk.push({1, 0, val[1]});
while (!stk.empty()) {
Node cur = stk.top();
stk.pop();
bool leaf = true;
for (int v : g[cur.u]) {
if (v != cur.p) {
leaf = false;
stk.push({v, cur.u, cur.s + val[v]});
}
}
if (leaf) {
if (cur.s % k == 0) {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
04 1月, 02:43

