結果

問題 No.1637 Easy Tree Query
ユーザー 沙耶花沙耶花
提出日時 2021-08-06 21:50:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 4,808 ms
コンパイル使用メモリ 264,536 KB
実行使用メモリ 17,316 KB
最終ジャッジ日時 2023-10-17 05:07:43
合計ジャッジ時間 12,072 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 263 ms
9,660 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 63 ms
6,492 KB
testcase_05 AC 221 ms
5,700 KB
testcase_06 AC 142 ms
5,172 KB
testcase_07 AC 76 ms
4,348 KB
testcase_08 AC 50 ms
5,964 KB
testcase_09 AC 171 ms
8,076 KB
testcase_10 AC 98 ms
4,680 KB
testcase_11 AC 236 ms
8,604 KB
testcase_12 AC 232 ms
7,548 KB
testcase_13 AC 36 ms
4,908 KB
testcase_14 AC 108 ms
8,340 KB
testcase_15 AC 219 ms
8,868 KB
testcase_16 AC 169 ms
9,396 KB
testcase_17 AC 64 ms
4,908 KB
testcase_18 AC 203 ms
5,700 KB
testcase_19 AC 198 ms
6,228 KB
testcase_20 AC 244 ms
7,284 KB
testcase_21 AC 122 ms
6,756 KB
testcase_22 AC 252 ms
9,660 KB
testcase_23 AC 62 ms
5,172 KB
testcase_24 AC 96 ms
6,756 KB
testcase_25 AC 223 ms
5,436 KB
testcase_26 AC 249 ms
7,548 KB
testcase_27 AC 282 ms
9,396 KB
testcase_28 AC 160 ms
5,436 KB
testcase_29 AC 190 ms
7,020 KB
testcase_30 AC 59 ms
7,020 KB
testcase_31 AC 176 ms
4,348 KB
testcase_32 AC 97 ms
5,436 KB
testcase_33 AC 208 ms
4,712 KB
testcase_34 AC 78 ms
17,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

vector<vector<int>> E;
vector<long long> ans;

void dfs(int cur,int p){
	ans[cur] = 1;
	rep(i,E[cur].size()){
		int to = E[cur][i];
		if(to==p)continue;
		dfs(to,cur);
		ans[cur] += ans[to];
	}
}

int main(){
	
	int n,q;
	cin>>n>>q;
	
	E.resize(n);
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		u--;v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	ans.resize(n,0);
	dfs(0,-1);
	long long A = 0;
	rep(_,q){
		long long p,x;
		cin>>p>>x;
		p--;
		A += x * ans[p];
		cout<<A<<endl;
	}
	
	return 0;
}
0