#include "happy.h"
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAXN=1e5*3+1;
vector<pair<int,int>>edges[MAXN];
bool active[MAXN];
bool visited[MAXN];
void dfs(int start, int n)
{
    if(!active[start]&&start<n){start++;dfs(start,n);}
    if(start>=n)return;
    if(visited[start])return;
    else visited[start]=1;
    for(auto child: edges[start])
    {
        int vr=child.first;
        if(active[vr]&&!!visited[vr])dfs(vr,n);
    }
}
int sum(int start, int finish,int n)
{
    if(start==finish)return 0;
    if(start>=n)return 0;
    int suma=0;
    for(auto child: edges[start])
    {
        int vr=child.first,hp=child.second;
        if(!active[vr])continue;
        suma+=hp;
        suma+=sum(vr, finish, n);
        suma-=hp;
    }
    return suma;
}
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) {
    for(int i=0;i<n;i++) // tree
    {
        int v1=u[i], v2=v[i], hp=h[i];
        edges[v1].push_back({v2, hp});
        edges[v2].push_back({v2, hp});
    }
    for(int i=0;i<q;i++)//queries
    {
        int t1=t[i],l1=l[i],r1=r[i];
        for(int j=l1;j<=r1;j++)
        {
            if(t1==1)
            {
                active[j]=1;
            }
            else
            {
                active[j]=0;
            }
        }
        //cout<<sum(1,2, n)<<endl;//dfs(0,n);
    }
}
