結果
問題 | No.1637 Easy Tree Query |
ユーザー | 👑 emthrm |
提出日時 | 2021-08-06 21:23:56 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 1,436 bytes |
コンパイル時間 | 2,287 ms |
コンパイル使用メモリ | 207,308 KB |
実行使用メモリ | 12,924 KB |
最終ジャッジ日時 | 2023-10-17 04:40:11 |
合計ジャッジ時間 | 6,087 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 60 ms
8,964 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 25 ms
6,324 KB |
testcase_05 | AC | 42 ms
5,428 KB |
testcase_06 | AC | 29 ms
5,000 KB |
testcase_07 | AC | 12 ms
4,348 KB |
testcase_08 | AC | 19 ms
5,620 KB |
testcase_09 | AC | 49 ms
7,644 KB |
testcase_10 | AC | 21 ms
4,672 KB |
testcase_11 | AC | 66 ms
8,172 KB |
testcase_12 | AC | 53 ms
7,116 KB |
testcase_13 | AC | 13 ms
4,748 KB |
testcase_14 | AC | 39 ms
7,908 KB |
testcase_15 | AC | 60 ms
8,436 KB |
testcase_16 | AC | 58 ms
8,964 KB |
testcase_17 | AC | 16 ms
4,744 KB |
testcase_18 | AC | 40 ms
5,428 KB |
testcase_19 | AC | 42 ms
5,844 KB |
testcase_20 | AC | 54 ms
6,856 KB |
testcase_21 | AC | 33 ms
6,324 KB |
testcase_22 | AC | 68 ms
8,964 KB |
testcase_23 | AC | 18 ms
5,060 KB |
testcase_24 | AC | 29 ms
6,324 KB |
testcase_25 | AC | 41 ms
5,268 KB |
testcase_26 | AC | 56 ms
7,160 KB |
testcase_27 | AC | 71 ms
8,700 KB |
testcase_28 | AC | 32 ms
5,256 KB |
testcase_29 | AC | 46 ms
6,852 KB |
testcase_30 | AC | 26 ms
6,652 KB |
testcase_31 | AC | 25 ms
4,348 KB |
testcase_32 | AC | 25 ms
5,332 KB |
testcase_33 | AC | 36 ms
4,704 KB |
testcase_34 | AC | 36 ms
12,924 KB |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { int n, q; cin >> n >> q; vector<vector<int>> graph(n); REP(_, n - 1) { int a, b; cin >> a >> b; --a; --b; graph[a].emplace_back(b); graph[b].emplace_back(a); } vector<int> sub(n, 1); auto f = [&](auto &&f, int par, int ver) -> void { for (int e : graph[ver]) { if (e == par) continue; f(f, ver, e); sub[ver] += sub[e]; } }; f(f, -1, 0); ll ans = 0; while (q--) { int p, x; cin >> p >> x; --p; ans += 1LL * sub[p] * x; cout << ans << '\n'; } return 0; }