#include "happy.h"
#include <bits/stdc++.h>
using namespace std;

void dfs(int cur, int prev, vector<int> &color, vector<vector<int> > &g)
{
    for(int &next : g[cur])
    {
        if(next == prev)continue;
        color[next] = (color[cur] + 1) % 2;
        dfs(next, cur, color, g);
    }
}

vector<long long int> happy (int N, int Q,
vector<int> u, vector<int> v, vector<int> h,
vector<int> t, vector<int> l, vector<int> r)
{
    int n = N;
    vector<int> open(n, 0);
    vector<long long> rez;

    vector<vector<int> > g(n);

    for(int i=0; i<n-1; i++)
    {
        int U = u[i];
        int V = v[i];

        g[U].push_back(V);
        g[V].push_back(U);
    }

    vector<int> color(n, 0);
    dfs(0, -1, color, g);

    int curSum = 0, on0 = 0, on1 = 0;

    for(int q = 0; q < Q; q++)
    {
        int point = l[q];
        int newState = t[q] % 2;

        if(newState == open[point]){rez.push_back(curSum); continue;}

        int curColor = color[point];

        if(newState == 0 && curColor == 0)curSum -= on1;
        if(newState == 1 && curColor == 0)curSum += on1;
        if(newState == 0 && curColor == 1)curSum -= on0;
        if(newState == 1 && curColor == 1)curSum += on0;

        rez.push_back(curSum);

        if(curColor == 0 && newState == 0)on0--;
        if(curColor == 0 && newState == 1)on0++;
        if(curColor == 1 && newState == 0)on1--;
        if(curColor == 1 && newState == 1)on1++;
    }

    return rez;
}