結果

問題 No.1637 Easy Tree Query
ユーザー kwm_tkwm_t
提出日時 2021-08-06 21:27:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,375 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 169,308 KB
実行使用メモリ 20,052 KB
最終ジャッジ日時 2023-10-17 04:53:07
合計ジャッジ時間 5,738 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,444 KB
testcase_01 AC 4 ms
8,448 KB
testcase_02 AC 60 ms
12,248 KB
testcase_03 AC 4 ms
8,444 KB
testcase_04 AC 27 ms
10,512 KB
testcase_05 AC 46 ms
9,932 KB
testcase_06 AC 32 ms
9,548 KB
testcase_07 AC 15 ms
8,540 KB
testcase_08 AC 21 ms
10,068 KB
testcase_09 AC 53 ms
11,476 KB
testcase_10 AC 24 ms
9,324 KB
testcase_11 AC 66 ms
11,796 KB
testcase_12 AC 60 ms
11,032 KB
testcase_13 AC 14 ms
9,380 KB
testcase_14 AC 45 ms
11,544 KB
testcase_15 AC 68 ms
11,936 KB
testcase_16 AC 66 ms
12,236 KB
testcase_17 AC 20 ms
9,376 KB
testcase_18 AC 43 ms
9,928 KB
testcase_19 AC 45 ms
10,228 KB
testcase_20 AC 60 ms
10,960 KB
testcase_21 AC 36 ms
10,564 KB
testcase_22 AC 75 ms
12,300 KB
testcase_23 AC 20 ms
9,584 KB
testcase_24 AC 33 ms
10,576 KB
testcase_25 AC 44 ms
9,812 KB
testcase_26 AC 63 ms
11,176 KB
testcase_27 AC 80 ms
12,160 KB
testcase_28 AC 35 ms
9,716 KB
testcase_29 AC 50 ms
10,832 KB
testcase_30 AC 33 ms
10,808 KB
testcase_31 AC 28 ms
8,464 KB
testcase_32 AC 28 ms
9,860 KB
testcase_33 AC 40 ms
9,348 KB
testcase_34 AC 39 ms
20,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
vector<int>to[200005];
long long ch[100005];
void dfs(int v, int d = 0, int p = -1) {
	ch[v] = 1;
	for (int e : to[v]) {
		if (p == e) continue;
		dfs(e, d + 1, v);
		ch[v] += ch[e];
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, q; cin >> n >> q;
	rep(i, n - 1) {
		int a, b; cin >> a >> b; a--; b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	dfs(0);
	long long ans = 0;
	while (q--) {
		int p, x; cin >> p >> x; p--;
		ans += ch[p] * x;
		cout << ans << endl;
	}
	return 0;
}
0