結果

問題 No.1637 Easy Tree Query
ユーザー ゆにぽけゆにぽけ
提出日時 2023-11-06 11:01:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 910 bytes
コンパイル時間 1,367 ms
コンパイル使用メモリ 129,300 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2023-11-06 11:01:47
合計ジャッジ時間 8,322 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,620 KB
testcase_01 AC 3 ms
6,624 KB
testcase_02 AC 59 ms
10,144 KB
testcase_03 AC 3 ms
6,620 KB
testcase_04 AC 25 ms
8,488 KB
testcase_05 AC 44 ms
7,964 KB
testcase_06 AC 31 ms
7,616 KB
testcase_07 AC 15 ms
6,708 KB
testcase_08 AC 20 ms
8,088 KB
testcase_09 AC 45 ms
9,356 KB
testcase_10 AC 22 ms
7,416 KB
testcase_11 AC 57 ms
9,648 KB
testcase_12 AC 53 ms
8,956 KB
testcase_13 AC 14 ms
7,464 KB
testcase_14 AC 38 ms
9,420 KB
testcase_15 AC 57 ms
9,784 KB
testcase_16 AC 60 ms
10,120 KB
testcase_17 AC 18 ms
7,460 KB
testcase_18 AC 41 ms
7,964 KB
testcase_19 AC 43 ms
8,232 KB
testcase_20 AC 53 ms
8,892 KB
testcase_21 AC 34 ms
8,536 KB
testcase_22 AC 63 ms
10,192 KB
testcase_23 AC 18 ms
7,648 KB
testcase_24 AC 29 ms
8,544 KB
testcase_25 AC 43 ms
7,856 KB
testcase_26 AC 58 ms
9,088 KB
testcase_27 AC 71 ms
10,032 KB
testcase_28 AC 35 ms
7,768 KB
testcase_29 AC 46 ms
8,780 KB
testcase_30 AC 26 ms
8,756 KB
testcase_31 AC 28 ms
6,640 KB
testcase_32 AC 26 ms
7,900 KB
testcase_33 AC 39 ms
7,436 KB
testcase_34 AC 36 ms
16,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
using namespace std;
int N,Q,ch[1 << 17];
vector<int> G[1 << 17];
void dfs(int u,int p)
{
	ch[u] = 1;
	for(int v:G[u]) if(v != p)
	{
		dfs(v,u);
		ch[u] += ch[v];
	}
}
void solve()
{
	cin >> N >> Q;
	for(int i = 1;i < N;i++)
	{
		int u,v;
		cin >> u >> v;
		u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(0,-1);
	long long ans = 0;
	for(;Q--;)
	{
		int p,x;
		cin >> p >> x;
		p--;
		ans += (long long)x*ch[p];
		cout << ans << "\n";
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) solve();
}
0