結果
問題 | No.1637 Easy Tree Query |
ユーザー | sten_san |
提出日時 | 2021-08-06 21:25:15 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 185 ms / 2,000 ms |
コード長 | 1,479 bytes |
コンパイル時間 | 2,670 ms |
コンパイル使用メモリ | 207,872 KB |
実行使用メモリ | 12,460 KB |
最終ジャッジ日時 | 2023-10-17 04:45:35 |
合計ジャッジ時間 | 8,421 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 177 ms
9,028 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 40 ms
6,388 KB |
testcase_05 | AC | 160 ms
5,488 KB |
testcase_06 | AC | 103 ms
5,060 KB |
testcase_07 | AC | 57 ms
4,348 KB |
testcase_08 | AC | 29 ms
5,680 KB |
testcase_09 | AC | 113 ms
7,708 KB |
testcase_10 | AC | 70 ms
4,732 KB |
testcase_11 | AC | 156 ms
8,236 KB |
testcase_12 | AC | 159 ms
7,180 KB |
testcase_13 | AC | 23 ms
4,808 KB |
testcase_14 | AC | 64 ms
7,972 KB |
testcase_15 | AC | 145 ms
8,500 KB |
testcase_16 | AC | 100 ms
9,028 KB |
testcase_17 | AC | 44 ms
4,804 KB |
testcase_18 | AC | 144 ms
5,488 KB |
testcase_19 | AC | 141 ms
5,904 KB |
testcase_20 | AC | 171 ms
6,916 KB |
testcase_21 | AC | 80 ms
6,388 KB |
testcase_22 | AC | 170 ms
9,028 KB |
testcase_23 | AC | 41 ms
5,120 KB |
testcase_24 | AC | 61 ms
6,388 KB |
testcase_25 | AC | 159 ms
5,332 KB |
testcase_26 | AC | 168 ms
7,220 KB |
testcase_27 | AC | 185 ms
8,764 KB |
testcase_28 | AC | 111 ms
5,316 KB |
testcase_29 | AC | 134 ms
6,916 KB |
testcase_30 | AC | 32 ms
6,712 KB |
testcase_31 | AC | 132 ms
4,348 KB |
testcase_32 | AC | 68 ms
5,392 KB |
testcase_33 | AC | 151 ms
4,764 KB |
testcase_34 | AC | 34 ms
12,460 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template <typename Element, typename Head, typename ...Args> auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template <typename Element, typename Head, typename ...Args> auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template <typename T, typename Compare = less<T>> T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); } template <typename T, typename Compare = less<T>> T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); } int main() { int n, q; cin >> n >> q; auto g = vec<int>(uns, n, 0); for (int i = 1; i < n; ++i) { int a, b; cin >> a >> b; --a; --b; g[a].push_back(b); g[b].push_back(a); } auto c = vec<int>(0, n); auto dfs = [&](auto &&self, int v, int p = -1) -> int { c[v] = 1; for (auto u : g[v]) { if (u == p) { continue; } c[v] += self(self, u, v); } return c[v]; }; dfs(dfs, 0); int64_t sum = 0; while (q--) { int p, x; cin >> p >> x; --p; sum += int64_t(x) * c[p]; cout << sum << endl; } }