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

using namespace std;

const int MAX_N = 3e5;

vector<pair<int, long long>> nbrs[MAX_N];

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) {
    int n = N, q = Q;
    vector<long long> ansv;
    for(int i = 0; i < n - 1; ++i) {
        nbrs[u[i]].push_back({v[i], h[i]});
        nbrs[v[i]].push_back({u[i], h[i]});
    }

    unordered_set<int> s;
    int curans = 0;
    for(int i = 0; i < q; ++i) {
        if(t[i] == 1)
        {
            s.insert(l[i]);
            for(auto [nbr, w] : nbrs[l[i]]) {
                if(s.find(nbr) != s.end()) {
                    curans ++;
                }
            }
        }
        else
        {
            s.erase(l[i]);
            for(auto [nbr, w] : nbrs[l[i]]) {
                if(s.find(nbr) != s.end()) {
                    curans --;
                }
            }

        }
        ansv.push_back(curans);
    }
    return ansv;
}
