結果

問題 No.1637 Easy Tree Query
ユーザー korogisukorogisu
提出日時 2021-08-06 22:19:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,167 bytes
コンパイル時間 4,579 ms
コンパイル使用メモリ 266,328 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-10-17 03:44:14
合計ジャッジ時間 13,398 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,744 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 257 ms
8,064 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
using ll = long long;
template<class T> inline bool chmin(T& a, T b) { if ( a > b ) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if ( a < b ) { a = b; return true; } return false; }

const int INF = 1 << 30;

void dfs(int v, vector<bool> &seen,vector<vector<int>>& G) {
    if(seen[v]) return;
    seen[v] = true;
    for(int& nv: G[v]) dfs(nv, seen, G);
}


int main() {
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> T(N);
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        T[a].emplace_back(b);
    }

    ll ans = 0;
    vector<bool> seen;
    vector<ll> s(N);
    for (int i = 0; i < Q; i++) {
        ll p, x, cnt;
        cin >> p >> x;
        p--;
        if(s[p] == 0)  {
            seen.assign(N,false);
            dfs(p,seen,T);
            s[p] = count(ALL(seen), true);
        }
        ans += s[p] * x;
        cout << ans << endl;
    }
    
    return 0;
}
0