#include "happy.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int depth[N];
vector <int> g[N];
void dfs(int v,int pr)
{
	for(auto u : g[v])
	{
		if(u == pr)continue;
		depth[u] = depth[v] + 1;
		dfs(u,v);
	}
}
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) {
	depth[1] = 1;
	dfs(1,0);
	for(int i = 0;i < n;i++)g[i].clear();
	for(int i = 0;i < n - 1;i++)
	{
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	int od = 0,ev = 0;
	vector <int> op(n);
	vector <int> ans;
	for(int i = 0;i < q;i++)
	{
		if(t[i] == 1)
		{
			if(!op[l[i]])
			{
				op[l[i]] = 1;
				if(depth[l[i]] % 2)
				{
					od++;
				}else
				{
					ev++;
				}
			}
		}else
		{
			if(op[l[i]])
			{
				op[l[i]] = 0;
				if(depth[l[i]] % 2)
				{
					od--;
				}else
				{
					ev--;
				}
			}
		}
		ans.push_back(ev * od);
	}
	return ans;
}
