結果

問題 No.1637 Easy Tree Query
ユーザー atjh16atjh16
提出日時 2021-09-09 21:42:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 529 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 167,768 KB
実行使用メモリ 9,660 KB
最終ジャッジ日時 2023-08-30 02:52:40
合計ジャッジ時間 10,128 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,692 KB
testcase_01 AC 4 ms
5,676 KB
testcase_02 AC 255 ms
9,592 KB
testcase_03 WA -
testcase_04 AC 62 ms
7,816 KB
testcase_05 AC 217 ms
7,148 KB
testcase_06 AC 142 ms
6,784 KB
testcase_07 AC 75 ms
5,804 KB
testcase_08 AC 49 ms
7,452 KB
testcase_09 AC 164 ms
8,672 KB
testcase_10 AC 98 ms
6,600 KB
testcase_11 AC 228 ms
8,980 KB
testcase_12 AC 227 ms
8,268 KB
testcase_13 AC 36 ms
6,620 KB
testcase_14 AC 105 ms
8,808 KB
testcase_15 AC 214 ms
9,244 KB
testcase_16 AC 156 ms
9,620 KB
testcase_17 AC 64 ms
6,640 KB
testcase_18 AC 200 ms
7,196 KB
testcase_19 AC 196 ms
7,500 KB
testcase_20 AC 241 ms
8,204 KB
testcase_21 AC 121 ms
7,916 KB
testcase_22 AC 254 ms
9,660 KB
testcase_23 AC 61 ms
6,896 KB
testcase_24 AC 96 ms
7,764 KB
testcase_25 AC 218 ms
7,192 KB
testcase_26 AC 246 ms
8,368 KB
testcase_27 AC 278 ms
9,464 KB
testcase_28 AC 157 ms
6,904 KB
testcase_29 AC 190 ms
8,096 KB
testcase_30 AC 59 ms
8,052 KB
testcase_31 AC 174 ms
5,896 KB
testcase_32 AC 97 ms
7,160 KB
testcase_33 AC 207 ms
6,632 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, q, a, b, p;
long long x, m = 0;
vector<int> e[100001];
long long r[100001];

int dfs(int f, int k) {
	if (e[k].size() == 1)
		return r[k] = 1;

	int t = 0;

	for (int j : e[k]) {
		if (j != f)
			t += dfs(k, j);
	}

	return r[k] = t + 1;
}

int main()
{
	cin >> n >> q;

	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;

		e[a].push_back(b);
		e[b].push_back(a);
	}

	dfs(-1, 1);

	for (int i = 0; i < q; i++) {
		cin >> p >> x;
		m += x * r[p];
		cout << m << endl;
	}	
}
0