結果

問題 No.900 aδδitivee
ユーザー niuezniuez
提出日時 2019-09-30 23:11:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,231 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 172,676 KB
実行使用メモリ 17,052 KB
最終ジャッジ日時 2024-04-14 08:24:46
合計ジャッジ時間 10,822 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
17,052 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 278 ms
9,088 KB
testcase_08 AC 276 ms
9,088 KB
testcase_09 AC 285 ms
9,088 KB
testcase_10 AC 267 ms
8,960 KB
testcase_11 AC 271 ms
9,216 KB
testcase_12 AC 274 ms
9,088 KB
testcase_13 AC 272 ms
9,216 KB
testcase_14 AC 275 ms
9,156 KB
testcase_15 AC 273 ms
9,048 KB
testcase_16 AC 275 ms
9,088 KB
testcase_17 AC 270 ms
9,088 KB
testcase_18 AC 280 ms
9,216 KB
testcase_19 AC 272 ms
9,216 KB
testcase_20 AC 274 ms
9,088 KB
testcase_21 AC 272 ms
8,908 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

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