結果

問題 No.1637 Easy Tree Query
ユーザー Example0911Example0911
提出日時 2021-08-06 21:24:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 204,664 KB
実行使用メモリ 17,144 KB
最終ジャッジ日時 2023-10-17 04:42:04
合計ジャッジ時間 8,991 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,908 KB
testcase_01 AC 4 ms
5,912 KB
testcase_02 AC 178 ms
10,280 KB
testcase_03 AC 4 ms
5,908 KB
testcase_04 AC 41 ms
7,904 KB
testcase_05 AC 158 ms
7,288 KB
testcase_06 AC 106 ms
6,932 KB
testcase_07 AC 60 ms
6,012 KB
testcase_08 AC 32 ms
7,416 KB
testcase_09 AC 116 ms
8,960 KB
testcase_10 AC 71 ms
6,724 KB
testcase_11 AC 165 ms
9,224 KB
testcase_12 AC 164 ms
8,432 KB
testcase_13 AC 26 ms
6,776 KB
testcase_14 AC 68 ms
8,960 KB
testcase_15 AC 153 ms
9,488 KB
testcase_16 AC 108 ms
9,752 KB
testcase_17 AC 47 ms
6,772 KB
testcase_18 AC 147 ms
7,288 KB
testcase_19 AC 141 ms
7,640 KB
testcase_20 AC 173 ms
8,432 KB
testcase_21 AC 82 ms
7,904 KB
testcase_22 AC 177 ms
10,016 KB
testcase_23 AC 44 ms
6,968 KB
testcase_24 AC 64 ms
7,904 KB
testcase_25 AC 161 ms
7,180 KB
testcase_26 AC 176 ms
8,696 KB
testcase_27 AC 197 ms
9,752 KB
testcase_28 AC 115 ms
7,088 KB
testcase_29 AC 136 ms
8,168 KB
testcase_30 AC 36 ms
8,168 KB
testcase_31 AC 136 ms
5,928 KB
testcase_32 AC 70 ms
7,224 KB
testcase_33 AC 155 ms
6,744 KB
testcase_34 AC 37 ms
17,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define int long long

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 1000000007;
int N, Q;
vector<int>G[100010];
vector<int>s;
void dfs(int v, int p) {
	for (auto nv : G[v]) {
		if (nv == p)continue;
		dfs(nv, v);
	}
	s[v] = 1;
	for (auto c : G[v]) {
		if (c == p)continue;
		s[v] += s[c];
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> Q;
	s.resize(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0, -1);
	int now = 0;
	for (int _ = 0; _ < Q; _++) {
		int p, x; cin >> p >> x; p--;
		now += s[p] * x;
		cout << now << endl;
	}
	return 0;


}

0