結果
問題 |
No.1637 Easy Tree Query
|
ユーザー |
|
提出日時 | 2022-03-06 12:45:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 570 bytes |
コンパイル時間 | 2,072 ms |
コンパイル使用メモリ | 171,664 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 22:00:26 |
合計ジャッジ時間 | 10,660 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 RE * 1 |
other | WA * 1 RE * 32 |
ソースコード
#include<bits/stdc++.h> using namespace std; int N,Q; vector<vector<long long>>G(N+3); vector<long long>cnt(N+3); vector<long long>B(N+3); void f(int i){ B[i]=1; for(long long j:G[i]){ if(B[j]==0){ f(j); cnt[i]=cnt[i]+cnt[j]; } } return; } int main(){ cin>>N>>Q; int answer=0; 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); } cnt[N-1]=1; f(0); for(int i=0;i<Q;i++){ int P,X; cin>>P>>X; answer=answer+cnt[P-1]*X; cout<<answer<<endl; } }