Submission #6993505


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

vector<int> graph[200000];
long long cnt[200000];
long long ans[200000];

void dfs(int cur, int parent, long long tmp_cnt) {
  ans[cur] = tmp_cnt + cnt[cur];
  for (int to: graph[cur]) {
    if (to == parent) {
      continue;
    }
    dfs(to, cur, ans[cur]);
  }
}
int main() {
  int n, q;
  cin>>n>>q;
  for (int i=0; i<n-1; i++) {
    int a, b;
    cin>>a>>b;
    --a; --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  for (int i=0; i<200000; i++) {
    cnt[i] = 0;
    ans[i] = 0;
  }
  for (int i=0; i<q; i++) {
    int p, x;
    cin>>p>>x;
    --p;
    cnt[p] += x;
  }
  dfs(0, -1, 0);
  cout<<ans[0];
  for (int i=1; i<n; i++) {
    cout<<" "<<ans[i];
  }
  cout<<endl;
}

Submission Info

Submission Time
Task D - Ki
User m44
Language C++14 (GCC 5.4.1)
Score 400
Code Size 784 Byte
Status AC
Exec Time 374 ms
Memory 25856 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 14
Set Name Test Cases
Sample a01, a02
All a01, a02, b03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14
Case Name Status Exec Time Memory
a01 AC 5 ms 8064 KB
a02 AC 5 ms 8064 KB
b03 AC 5 ms 8064 KB
b04 AC 365 ms 25600 KB
b05 AC 336 ms 25856 KB
b06 AC 292 ms 16116 KB
b07 AC 276 ms 17012 KB
b08 AC 356 ms 21368 KB
b09 AC 351 ms 15488 KB
b10 AC 373 ms 22528 KB
b11 AC 351 ms 19968 KB
b12 AC 354 ms 18304 KB
b13 AC 374 ms 24064 KB
b14 AC 299 ms 15988 KB