結果

問題 No.900 aδδitivee
ユーザー niuez
提出日時 2019-09-30 23:11:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,231 bytes
コンパイル時間 1,928 ms
コンパイル使用メモリ 176,352 KB
実行使用メモリ 17,060 KB
最終ジャッジ日時 2024-10-03 05:30:48
合計ジャッジ時間 9,448 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 N;
  cin >> N;
  vector<i64> p(N);
  vector<i64> w(N);
  vector<vector<i64>> G(N);
  for(int i = 0;i < N - 1;i++) {
    i64 a, b, c;
    cin >> a >> b >> c;
    p[b] = a;
    w[b] = c;
    G[a].push_back(b);
  }

  i64 Q;
  cin >> Q;
  for(int i = 0;i < Q;i++) {
    i64 type = 0;
    cin >> type;
    if(type == 1) {
      i64 a, x;
      cin >> a >> x;
      queue<i64> que;
      que.push(a);
      while(!que.empty()) {
        i64 v = que.front();
        que.pop();
        for(auto to: G[v]) {
          w[to] += x;
          que.push(to);
        }
      }
    }
    else {
      i64 b;
      cin >> b;
      i64 ans = 0;
      while(b != 0) {
        ans += w[b];
        b = p[b];
      }
      cout << ans << endl;
    }
  } 
}
0