結果

問題 No.1637 Easy Tree Query
ユーザー atjh16atjh16
提出日時 2021-09-09 21:57:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 3,391 ms
コンパイル使用メモリ 167,564 KB
実行使用メモリ 13,008 KB
最終ジャッジ日時 2023-08-30 03:09:52
合計ジャッジ時間 10,566 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,664 KB
testcase_01 AC 3 ms
5,688 KB
testcase_02 AC 254 ms
9,584 KB
testcase_03 AC 4 ms
5,864 KB
testcase_04 AC 59 ms
7,704 KB
testcase_05 AC 222 ms
7,128 KB
testcase_06 AC 138 ms
6,740 KB
testcase_07 AC 75 ms
5,752 KB
testcase_08 AC 48 ms
7,272 KB
testcase_09 AC 169 ms
8,672 KB
testcase_10 AC 98 ms
6,520 KB
testcase_11 AC 227 ms
9,048 KB
testcase_12 AC 230 ms
8,220 KB
testcase_13 AC 37 ms
6,616 KB
testcase_14 AC 105 ms
8,732 KB
testcase_15 AC 215 ms
9,192 KB
testcase_16 AC 157 ms
9,512 KB
testcase_17 AC 63 ms
6,568 KB
testcase_18 AC 197 ms
7,148 KB
testcase_19 AC 193 ms
7,440 KB
testcase_20 AC 241 ms
8,176 KB
testcase_21 AC 119 ms
7,784 KB
testcase_22 AC 246 ms
9,596 KB
testcase_23 AC 62 ms
6,884 KB
testcase_24 AC 92 ms
7,776 KB
testcase_25 AC 222 ms
7,092 KB
testcase_26 AC 244 ms
8,388 KB
testcase_27 AC 275 ms
9,432 KB
testcase_28 AC 155 ms
7,048 KB
testcase_29 AC 185 ms
8,056 KB
testcase_30 AC 56 ms
8,000 KB
testcase_31 AC 171 ms
5,676 KB
testcase_32 AC 97 ms
7,268 KB
testcase_33 AC 208 ms
6,676 KB
testcase_34 AC 69 ms
13,008 KB
権限があれば一括ダウンロードができます

ソースコード

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 ct(int f, int k) {
	int t = 1;

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

	return r[k] = t;
}

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);
	}

	ct(-1, 1);

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