結果

問題 No.1637 Easy Tree Query
ユーザー hiro71687khiro71687k
提出日時 2023-08-26 23:40:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 1,047 bytes
コンパイル時間 6,469 ms
コンパイル使用メモリ 261,936 KB
実行使用メモリ 19,440 KB
最終ジャッジ日時 2023-08-26 23:41:00
合計ジャッジ時間 15,350 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 255 ms
12,220 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 63 ms
7,300 KB
testcase_05 AC 212 ms
6,864 KB
testcase_06 AC 136 ms
5,736 KB
testcase_07 AC 75 ms
4,380 KB
testcase_08 AC 49 ms
6,312 KB
testcase_09 AC 167 ms
9,532 KB
testcase_10 AC 96 ms
5,684 KB
testcase_11 AC 234 ms
10,472 KB
testcase_12 AC 227 ms
9,156 KB
testcase_13 AC 36 ms
5,228 KB
testcase_14 AC 109 ms
9,420 KB
testcase_15 AC 218 ms
10,760 KB
testcase_16 AC 167 ms
11,224 KB
testcase_17 AC 62 ms
5,304 KB
testcase_18 AC 195 ms
7,060 KB
testcase_19 AC 192 ms
7,488 KB
testcase_20 AC 241 ms
9,020 KB
testcase_21 AC 118 ms
7,688 KB
testcase_22 AC 250 ms
11,568 KB
testcase_23 AC 61 ms
5,760 KB
testcase_24 AC 96 ms
7,444 KB
testcase_25 AC 220 ms
6,644 KB
testcase_26 AC 246 ms
9,232 KB
testcase_27 AC 276 ms
11,376 KB
testcase_28 AC 155 ms
6,536 KB
testcase_29 AC 187 ms
8,584 KB
testcase_30 AC 59 ms
7,556 KB
testcase_31 AC 170 ms
4,380 KB
testcase_32 AC 94 ms
6,544 KB
testcase_33 AC 202 ms
5,764 KB
testcase_34 AC 74 ms
19,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=998244353;
ll inf=1009999999999999990;
void dfs(ll now,vector<vector<ll>>&g,vector<ll>&dp,vector<ll>&memo){
    memo[now]=1;
    dp[now]=1;
    for (ll i = 0; i < g[now].size(); i++)
    {
        if (memo[g[now][i]]==0)
        {
            dfs(g[now][i],g,dp,memo);
            dp[now]+=dp[g[now][i]];
        }
    }
}
int main(){
    ll n,q;
    cin >>n >> q;
    vector<vector<ll>>g(n);
    for (ll i = 0; i < n-1; i++)
    {
        ll a,b;
        cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll>dp(n,0);
    vector<ll>memo(n,0);
    dfs(0,g,dp,memo);
    ll ans=0;
    vector<ll>a;
    for (ll i = 0; i < q; i++)
    {
        ll p,x;
        cin >> p >> x;
        p--;
        ans+=x*dp[p];
        a.push_back(ans);
    }
    for (ll i = 0; i < a.size(); i++)
    {
        cout << a[i] << endl;
    }
    
}
0