DSU problem

problem link-

I HAVE USE DISJOINT SET TO SOLVE THIS PROBLEM BUT I AM GETTING WA CAN ANY ONE HELP WHATS WRONG WITH MY SOLUTION. THE CODE IS LOOKING BIG BUT IS NORMAL DSU SO CAN U PLZZ LOOK ONCE

i have stored pair of parent node and weight in ‘mp’ and the i have added things with same weight in ‘mp’ to get the ans

ll n,m;
cin>>n>>m;

vector<tuple<ll,ll,ll>> edge(n-1);// wt ,u,v
for(auto &x:edge){
    cin>>get<1>(x);
    cin>>get<2>(x);
    cin>>get<0>(x);
    get<1>(x)--;
    get<2>(x)--;
}

sort(edge.begin(),edge.end());



vector<ll> head(n);
vector<ll> size(n);
for(int i=0;i<n;i++){
    head[i]=i;
    size[i]=1;
}


map<pair<ll,ll>,ll> mp;
for(auto x:edge){
    ll n1=get<1>(x);
    ll n2=get<2>(x);
    
    while(n1!=head[n1]){
        n1=head[n1];
    }
    while(n2!=head[n2]){
        n2=head[n2];
    }
    
    if(n1!=n2){
        if(size[n1]<size[n2]){
            head[n1]=n2;
            size[n2]+=size[n1];
            mp[{n2,get<0>(x)}]=(size[n2]*(size[n2]-1))/2;

        }else{
            head[n2]=n1;
            size[n1]+=size[n2];
            mp[{n1,get<0>(x)}]=(size[n1]*(size[n1]-1))/2;
        }
    }        
}

map<ll,ll> tmp;
for(auto x:mp){
    tmp[x.first.second]+=x.second;
}

vector<ll> weight;
for(auto x:edge){
    weight.push_back(get<0>(x));
}

for(int i=0;i<m;i++){
    ll w;
    cin>>w;
    auto tt=upper_bound(weight.begin(),weight.end(),w);
    if(tt==weight.begin()) cout<<0<<" "<<flush;
    else{
        ll t=tt-weight.begin();
        t--;
        cout<<tmp[weight[t]]<<" "<<flush;
    }
}
cout<<endl;