#include "happy.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<vector<pair<ll, ll>>> g;
vector<ll> ost;

void dfs(ll v, ll p, ll cost)
{
    ost[v] = cost;
    for (auto u : g[v])
    {
        if (u.first != p)
        {
            dfs(u.first, v, (1 - cost));
        }
    }
}

void coutv(vector<ll> v) {
    for (auto u : v) {
        cout << u << endl;
    }
}

std::vector <long long int> happy (int N, int Q, std::vector <int> u, std::vector <int> v, std::vector <int> h, std::vector <int> t, std::vector <int> l, std::vector <int> r) {
    ll ch = 0;
    ll nch = 0;
    ost.resize(N);
    g.resize(N);
    for (ll i = 0; i < N - 1; i++) {
        g[u[i]].push_back({ v[i], h[i] });
        g[v[i]].push_back({ u[i], h[i] });
    }
    dfs(0, -1, 0);
    vector<bool> used(N, 0);
    vector<ll> ans(Q, 0);
    ll cans = 0;
    for (ll i = 0; i < Q; i++) {
        if (t[i] == 1 && !used[l[i]]) {
            if (ost[l[i]])
            {
                nch++;
                cans += ch;
            } else
            {
                ch++;
                cans += nch;
            }
            used[l[i]] = 1;
        }
        else if (t[i] == 2 && used[l[i]]) {
            if (ost[l[i]])
            {
                nch--;
                cans -= ch;
            } else
            {
                ch--;
                cans -= nch;
            }
            used[l[i]] = 0;
        }
        ans[i] = cans;
    }
    //coutv(ans);
    return ans;
}

/*int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> u(N);
    vector<int> v(N);
    vector<int> h(N);
    vector<int> t(Q);
    vector<int> l(Q);
    vector<int> r(Q);
    for (ll i = 0; i < N - 1; i++) {
        cin >> u[i];
    }
    for (ll i = 0; i < N - 1; i++) {
        cin >> v[i];
    }
    for (ll i = 0; i < N - 1; i++) {
        cin >> h[i];
    }
    for (ll i = 0; i < Q; i++) {
        cin >> t[i];
    }
    for (ll i = 0; i < Q; i++) {
        cin >> l[i];
    }
    for (ll i = 0; i < Q; i++) {
        cin >> r[i];
    }
    happy(N, Q, u, v, h, t, l, r);
}*/
