Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;

using vec = vector < ll >;
 
template < typename T > using index_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)


const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
vector<ll>adj[200001];
vector<bool>visit(200001,false);
vec order;
ll n,q;
vec size(200002,0);
ll les=1;
map<ll,ll>maps;
void dfstree(ll s)
{


    visit[s]=true;
    size[s]=1;
    order.pb(s);
    for(auto u:adj[s])
    {
        if(visit[u])
        {
            continue;
        }
        dfstree(u);
        size[s]+=size[u];

    }
}
struct fenwicktree
{
    ll n;
    vector<ll>bit;
    fenwicktree(ll n)
    {
        this->n=n;
        bit.assign(n,0);
    }
    void add(ll idx,ll val)
    {
        for(;idx<n;idx=(idx|(idx+1)))
        {
            bit[idx]+=val;
        }
    }
    void range_add(ll l, ll r,ll val) {
        add(l, val);
        add(r + 1, -1*val);
    }
    ll sum(ll r) {
        ll ret = 0;
        for (; r >= 0; r = ((r & (r + 1)) - 1))
            ret += bit[r];
        return ret;
    }

};







int main() 
{
    #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt","w",stdout);
    #endif

    fast();
      


        cin>>n>>q;
        size.resize(n);
        ll i,x,y;
        f(i,0,n-1)
        {
         cin>>x>>y;
         x--;
         y--;
         adj[x].pb(y);
         adj[y].pb(x);  
         
    
        }

        dfstree(0);
        // cout<<"order of dfs is:"<<edl;
        // for(auto s:order)
        // {
        //     cout<<s<<" ";
        // }
        f(i,0,n)
        {
            maps[order[i]]=i;
        }
        // cout<<"\nsize of each subtree  is "<<edl;
        // for(auto s:size)
        // {
        //     cout<<s<<edl;
        // }
        ll xx,val,result[n];
        fenwicktree fen(n);
      
        f(i,0,q)
        {
            cin>>xx>>val;
            xx--;
            fen.range_add(maps[xx],maps[xx]+size[xx]-1,val);
        }
        f(i,0,n)
        {
            result[i]=fen.sum(i);
            cout<<result[i]<<" ";
           
        }
        


        
  

    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;

 
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;

using vec = vector < ll >;
 
template < typename T > using index_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)


const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
vector<ll>adj[200001];
vector<bool>visit(200001,false);
vec order;
ll n,q;
vec size(200002,0);
ll les=1;
map<ll,ll>maps;
void dfstree(ll s)
{


    visit[s]=true;
    size[s]=1;
    order.pb(s);
    for(auto u:adj[s])
    {
        if(visit[u])
        {
            continue;
        }
        dfstree(u);
        size[s]+=size[u];

    }
}
struct fenwicktree
{
    ll n;
    vector<ll>bit;
    fenwicktree(ll n)
    {
        this->n=n;
        bit.assign(n,0);
    }
    void add(ll idx,ll val)
    {
        for(;idx<n;idx=(idx|(idx+1)))
        {
            bit[idx]+=val;
        }
    }
    void range_add(ll l, ll r,ll val) {
        add(l, val);
        add(r + 1, -1*val);
    }
    ll sum(ll r) {
        ll ret = 0;
        for (; r >= 0; r = ((r & (r + 1)) - 1))
            ret += bit[r];
        return ret;
    }

};







int main() 
{
 

    fast();
      


        cin>>n>>q;
        size.resize(n);
        ll i,x,y;
        f(i,0,n-1)
        {
         cin>>x>>y;
         x--;
         y--;
         adj[x].pb(y);
         adj[y].pb(x);  
         
    
        }

        dfstree(0);
        // cout<<"order of dfs is:"<<edl;
        // for(auto s:order)
        // {
        //     cout<<s<<" ";
        // }
        f(i,0,n)
        {
            maps[order[i]]=i;
        }
        // cout<<"\nsize of each subtree  is "<<edl;
        // for(auto s:size)
        // {
        //     cout<<s<<edl;
        // }
        ll xx,val,result[n];
        fenwicktree fen(n);
      
        f(i,0,q)
        {
            cin>>xx>>val;
            xx--;
            fen.range_add(maps[xx],maps[xx]+size[xx]-1,val);
        }
        f(i,0,n)
        {
            result[i]=fen.sum(i);
            cout<<result[i]<<" ";
           
        }
        


        
  

    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;

 
}


Compiler output:
a.cc: In function 'void dfstree(ll)':
a.cc:46:5: error: reference to 'visit' is ambiguous
   46 |     visit[s]=true;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:36:13: note:                 'std::vector<bool> visit'
   36 | vector<bool>visit(200001,false);
      |             ^~~~~
a.cc:47:5: error: reference to 'size' is ambiguous
   47 |     size[s]=1;
      |     ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:39:5: note:                 'vec size'
   39 | vec size(200002,0);
      |     ^~~~
a.cc:51:12: error: reference to 'visit' is ambiguous
   51 |         if(visit[u])
      |            ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:36:13: note:                 'std::vector<bool> visit'
   36 | vector<bool>visit(200001,false);
      |             ^~~~~
a.cc:56:9: error: reference to 'size' is ambiguous
   56 |         size[s]+=size[u];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:39:5: note:                 'vec size'
   39 | vec size(200002,0);
      |     ^~~~
a.cc:56:18: error: reference to 'size' is ambiguous
   56 |         size[s]+=size[u];
      |                  ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:39:5: note:                 'vec size'
   39 | vec size(200002,0);
      |     ^~~~
a.cc: In function 'int main()':
a.cc:107:9: error: reference to 'size' is ambiguous
  107 |         size.resize(n);
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:39:5: note:                 'vec size'
   39 | vec size(200002,0);
      |     ^~~~
a.cc:142:45: error: reference to 'size' is ambiguous
  142 |             fen.range_add(maps[xx],maps[xx]+size[xx]-1,val);
      |                                             ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:39:5: note:                 'vec size'
   39 | vec size(200002,0);
      |     ^~~~
a.cc: At global scope:
a.cc:192:11: error: redefinition of 'const int MOD'
  192 | const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
      |           ^~~
a.cc:32:11: note: 'const int MOD' previously defined here
   32 | const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
      |           ^~~
a.cc:192:26: error: redefinition of 'const int INF'
  192 | const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
      |                          ^~~
a.cc:32:26: note: 'const int INF' previously defined here
   32 | const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
      |                          ^~~
a.cc:192:41: error: redefinition of 'const int N'
  192 | const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
      |                                         ^
a.cc:32:41: note: 'const int N' previously defined here
   32 | const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
      |                                         ^
a.cc:193:14: error: redefinition of 'const double PI'
  193 | const double PI = acos(-1);
      |              ^~
a.cc:33:14: note: 'const double PI' previously defined here
   33 | const double PI = acos(-1);
      |              ^~
a.cc:194:10: error: redefinition of 'const ll LINF'
  194 | const ll LINF = LLONG_MAX;
      |          ^~~~
a.cc:34:10: note: 'const ll LINF' previously defined here
   34 | const ll LINF = LLONG_MAX;
      |          ^~~~
a.cc:195:11: error: redefinition of 'std::vector<long long int> adj [200001]'
  195 | vector<ll>adj[200001];
      |           ^~~
a.cc:35:11: note: 'std::vector<long long int> adj [200001]' previously declared here
   35 | vector<ll>adj[200001];
      |           ^~~
a.cc:196:13: error: redefinition of 'std::vector<bool> visit'
  196 | vector<bool>visit(200001,false);
      |             ^~~~~
a.cc:36:13: note: 'std::vector<bool> visit' previously declared here
   36 | vector<bool>visit(200001,false);
      |             ^~~~~
a.cc:197:5: error: redefinition of 'vec order'
  197 | vec order;
      |     ^~~~~
a.cc:37:5: note: 'vec order' previously declared here
   37 | vec order;
      |     ^~~~~
a.cc:198:4: error: redefinition of 'll n'
  198 | ll n,q;
      |    ^
a.cc:38:4: note: 'll n' previously declared here
   38 | ll n,q;
      |    ^
a.cc:198:6: error: redefinition of 'll q'
  198 | ll n,q;
      |      ^
a.cc:38:6: note: 'll q' previously declared here
   38 | ll n,q;
      |      ^
a.cc:199:5: error: redefinition of 'vec size'
  199 | vec size(200002,0);
      |     ^~~~
a.cc:39:5: note: 'vec size' previously declared here
   39 | vec size(200002,0);
      |     ^~~~
a.cc:200:4: error: redefinition of 'll les'
  200 | ll les=1;
      |    ^~~
a.cc:40:4: note: 'll les' previously defined here
   40 | ll les=1;
      |    ^~~
a.cc:201:11: error: redefinition of 'std::map<long long int, long long int> maps'
  201 | map<ll,ll>maps;
      |           ^~~~
a.cc:41:11: note: 'std::map<long long int, long long int> maps' previously declared here
   41 | map<ll,ll>maps;
      |           ^~~~
a.cc:202:6: error: redefinition of 'void dfstree(ll)'
  202 | void dfstree(ll s)
      |      ^~~~~~~
a.cc:42:6: note: 'void dfstree(ll)' previously defined here
   42 | void dfstree(ll s)
      |      ^~~~~~~
a.cc: In function 'void dfstree(ll)':
a.cc:206:5: error: reference to 'visit' is ambiguous
  206 |     visit[s]=true;
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:36:13: note:                 'std::vector<bool> visit'
   36 | vector<bool>visit(200001,false);
      |             ^~~~~
a.cc:207:5: error: reference to 'size' is ambiguous
  207 |     size[s]=1;
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:39:5: note:                 'vec size'
   39 | vec size(200002,0);
      |     ^~~~
a.cc:211:12: error: reference to 'visit' is ambiguous
  211 |         if(visit[u])
      |            ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:36:13: note:                 'std::vector<bool> visit'
   36 | vector<bool>visit(200001,false);
      |             ^~~~~
a.cc:216:9: error: reference to 'size' is ambiguous
  216 |         size[s]+=size[u];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept