結果

問題 No.1637 Easy Tree Query
ユーザー kotatsugamekotatsugame
提出日時 2021-08-06 21:23:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 416 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 70,012 KB
実行使用メモリ 16,424 KB
最終ジャッジ日時 2023-10-17 04:36:39
合計ジャッジ時間 8,038 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,664 KB
testcase_01 AC 3 ms
6,668 KB
testcase_02 AC 259 ms
10,180 KB
testcase_03 AC 3 ms
6,624 KB
testcase_04 AC 57 ms
8,524 KB
testcase_05 AC 216 ms
8,000 KB
testcase_06 AC 140 ms
7,652 KB
testcase_07 AC 76 ms
6,744 KB
testcase_08 AC 47 ms
8,124 KB
testcase_09 AC 158 ms
9,392 KB
testcase_10 AC 97 ms
7,452 KB
testcase_11 AC 221 ms
9,684 KB
testcase_12 AC 224 ms
8,992 KB
testcase_13 AC 37 ms
7,500 KB
testcase_14 AC 99 ms
9,456 KB
testcase_15 AC 206 ms
9,816 KB
testcase_16 AC 151 ms
10,156 KB
testcase_17 AC 64 ms
7,496 KB
testcase_18 AC 197 ms
8,000 KB
testcase_19 AC 192 ms
8,268 KB
testcase_20 AC 236 ms
8,928 KB
testcase_21 AC 117 ms
8,572 KB
testcase_22 AC 239 ms
10,228 KB
testcase_23 AC 62 ms
7,684 KB
testcase_24 AC 96 ms
8,580 KB
testcase_25 AC 218 ms
7,892 KB
testcase_26 AC 245 ms
9,124 KB
testcase_27 AC 271 ms
10,068 KB
testcase_28 AC 156 ms
7,804 KB
testcase_29 AC 187 ms
8,816 KB
testcase_30 AC 57 ms
8,792 KB
testcase_31 AC 175 ms
6,676 KB
testcase_32 AC 98 ms
7,936 KB
testcase_33 AC 207 ms
7,472 KB
testcase_34 AC 76 ms
16,424 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int N,Q;
vector<int>G[1<<17];
int ch[1<<17];
int dfs(int u,int p)
{
	ch[u]=1;
	for(int v:G[u])if(v!=p)ch[u]+=dfs(v,u);
	return ch[u];
}
main()
{
	cin>>N>>Q;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(1,0);
	long ans=0;
	for(int i=0;i<Q;i++)
	{
		int p,x;cin>>p>>x;
		cout<<(ans+=(long)x*ch[p])<<endl;
	}
}
0