#include <vector>
#include <queue>
using namespace std;

vector<vector<int>> g;

vector<long long> happy(int n, int q, vector<int> u, vector<int> v, vector<int> h, vector<int> t, vector<int> l, vector<int> r){
    vector<long long> re;
    g.assign(n, {});
    vector<bool> o(n), p(n), z(n);
    int pc[2] = {1, 0};

    for (int i = 0; i < n-1; i++){
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }
    queue<int> qu;
    qu.push(0);
    z[0] = 1;
    while (!u.empty()){
        int u = qu.front();
        qu.pop();

        for (int v : g[u]){
            if (!z[v]){
                z[v] = 1;
                p[v] = !p[u];
                pc[p[v]]++;
                qu.push(v);
            }
        }
    }
return {};
    long long s = 0;
    for (int iq = 0; iq < q; iq++){
        s += pc[p[l[iq]]]*(2 - t[iq] - o[l[iq]]);
        o[l[iq]] = 2 - t[iq];
        re.push_back(s);
    }

    return re;
}
