fork download
  1. // ROOT : DRAGON3012009
  2. #include <bits/stdc++.h>
  3. #define ll long long
  4. #define ld long double
  5. #define el "\n"
  6. #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  7. #define __ROOT__ int main()
  8. #pragma GCC optimize("O2")
  9. #define FOR(i,l,r) for(int i = l ; i <= r ; i ++)
  10. #define FORD(i,r,l) for(int i = r ; i >= l ; i --)
  11. #define REP(i, a ) for(int i = 0 ; i < a ; i ++ )
  12. #define fi first
  13. #define se second
  14. #define M 1000000007
  15. #define MAXN 1000001
  16. #define INF (1ll<<30)
  17. #define BLOCK_SIZE 425
  18. #define MAX_NODE 1001001
  19. #define LOG 19
  20. #define ALPHA_SIZE 26
  21. #define BASE 311
  22. #define NAME "file"
  23. #define compare(v) sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end());
  24. using namespace std;
  25. const ll MOD[] = {(ll)1e9 + 2277, (ll)1e9 + 5277, (ll)1e9 + 8277, (ll)1e9 + 9277, (ll) 1e9 + 7 };
  26. const ll NMOD = 1;
  27. const int dx[] = {-1, 0, 1,0};
  28. const int dy[] = {0, 1, 0, -1};
  29. //**Variable**//
  30. ll n , q ;
  31. ll Nodeval[MAXN];
  32. vector<ll> adj[MAXN] ;
  33. vector<ll> heavy[MAXN] ;
  34. ll lazy[MAXN] ;
  35. ll deg[MAXN] ;
  36. //**Struct**//
  37.  
  38. //**Function**//
  39. template<class X, class Y >
  40. bool minimize(X & x, const Y &y ) {
  41. return x > y ? x = y, 1:0 ;
  42. }
  43. template<class X, class Y >
  44. bool maximize(X &x, const Y &y ) {
  45. return x < y ? x = y, 1:0 ;
  46. }
  47.  
  48. void init() {
  49. cin>>n>> q ;
  50. FOR(i , 1 , n - 1) {
  51. ll x, y ; cin >> x >> y ;
  52. adj[x].push_back(y) ;
  53. adj[y].push_back(x) ;
  54. deg[x] ++ ;
  55. deg[y] ++ ;
  56. }
  57. FOR(u , 1 , n) {
  58. for(ll v : adj[u]) {
  59. if(deg[u] > BLOCK_SIZE || deg[v] > BLOCK_SIZE ) {
  60. heavy[u].push_back(v) ;
  61. }
  62. }
  63. }
  64. }
  65.  
  66. void solve() {
  67. FOR(i , 1 , q) {
  68. ll t, u , x ; cin >> t >> u ;
  69. if(t == 1 ) {
  70. cin >> x ;
  71. if(deg[u] > BLOCK_SIZE) lazy[u] += x ;
  72. else {
  73. for(ll v : adj[u]) Nodeval[v] += x ;
  74. }
  75. }else {
  76. ll res = Nodeval[u] ;
  77. for(ll v : heavy[u]) res += lazy[v] ;
  78. cout<< res <<el;
  79. }
  80. }
  81. }
  82.  
  83. __ROOT__ {
  84. // freopen(NAME".inp" , "r" , stdin);
  85. // freopen(NAME".out" , "w", stdout) ;
  86. fast;
  87. int t =1 ;// cin >> t;
  88. while(t-- ) {
  89. init();
  90. solve();
  91. }
  92. }
Success #stdin #stdout 0.01s 52744KB
stdin
Standard input is empty
stdout
Standard output is empty