結果

問題 No.1637 Easy Tree Query
ユーザー fumofumofunifumofumofuni
提出日時 2021-08-06 22:04:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 1,356 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 206,012 KB
実行使用メモリ 14,108 KB
最終ジャッジ日時 2023-10-17 05:10:13
合計ジャッジ時間 9,603 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,216 KB
testcase_01 AC 4 ms
6,216 KB
testcase_02 AC 259 ms
10,412 KB
testcase_03 AC 4 ms
6,216 KB
testcase_04 AC 59 ms
8,300 KB
testcase_05 AC 215 ms
7,772 KB
testcase_06 AC 142 ms
7,508 KB
testcase_07 AC 77 ms
6,216 KB
testcase_08 AC 49 ms
8,036 KB
testcase_09 AC 161 ms
9,356 KB
testcase_10 AC 98 ms
7,244 KB
testcase_11 AC 225 ms
9,620 KB
testcase_12 AC 227 ms
8,828 KB
testcase_13 AC 37 ms
7,244 KB
testcase_14 AC 100 ms
9,356 KB
testcase_15 AC 212 ms
9,620 KB
testcase_16 AC 154 ms
10,148 KB
testcase_17 AC 65 ms
7,244 KB
testcase_18 AC 200 ms
7,772 KB
testcase_19 AC 195 ms
8,036 KB
testcase_20 AC 240 ms
8,828 KB
testcase_21 AC 117 ms
8,300 KB
testcase_22 AC 240 ms
10,148 KB
testcase_23 AC 62 ms
7,508 KB
testcase_24 AC 95 ms
8,300 KB
testcase_25 AC 222 ms
7,772 KB
testcase_26 AC 241 ms
8,828 KB
testcase_27 AC 266 ms
9,884 KB
testcase_28 AC 158 ms
7,508 KB
testcase_29 AC 198 ms
8,564 KB
testcase_30 AC 55 ms
8,564 KB
testcase_31 AC 175 ms
6,216 KB
testcase_32 AC 98 ms
7,772 KB
testcase_33 AC 207 ms
7,244 KB
testcase_34 AC 74 ms
14,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}
vvl g(100010);
vl dp(100010);
ll dfs(ll v,ll par=-1){
  dp[v]=1;
  for(auto p:g[v]){
    if(p==par)continue;
    dp[v]+=dfs(p,v);
  }
  return dp[v];
}
int main(){
  ll n,q;cin >> n >> q;
  rep(i,n-1){
    ll a,b;cin >> a >> b;a--;b--;
    g[a].push_back(b);g[b].push_back(a);
  }
  dfs(0);
  ll ans=0;
  while(q--){
    ll x,y;cin >> x >> y;x--;
    ans+=dp[x]*y;
    cout << ans <<endl;
  }
    
}
0