結果
| 問題 |
No.1637 Easy Tree Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-06 21:23:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 289 ms / 2,000 ms |
| コード長 | 416 bytes |
| コンパイル時間 | 653 ms |
| コンパイル使用メモリ | 70,256 KB |
| 実行使用メモリ | 16,152 KB |
| 最終ジャッジ日時 | 2024-09-17 03:20:21 |
| 合計ジャッジ時間 | 8,187 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 |
コンパイルメッセージ
main.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main()
| ^~~~
ソースコード
#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;
}
}