Submission #7016716


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 786 Byte
Status AC
Exec Time 367 ms
Memory 25856 KB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 400 / 400 0 / 0
Status
AC × 2
AC × 14
AC × 3
Set Name Test Cases
Sample a01, a02
All a01, a02, b03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14
after_contest after_contest_15, after_contest_16, after_contest_17
Case Name Status Exec Time Memory
a01 AC 4 ms 8064 KB
a02 AC 4 ms 8064 KB
after_contest_15 AC 4 ms 8064 KB
after_contest_16 AC 360 ms 25600 KB
after_contest_17 AC 351 ms 15744 KB
b03 AC 4 ms 8064 KB
b04 AC 355 ms 25600 KB
b05 AC 332 ms 25856 KB
b06 AC 288 ms 16116 KB
b07 AC 248 ms 17012 KB
b08 AC 353 ms 21368 KB
b09 AC 340 ms 15488 KB
b10 AC 348 ms 22528 KB
b11 AC 345 ms 19968 KB
b12 AC 353 ms 18304 KB
b13 AC 367 ms 24064 KB
b14 AC 287 ms 15988 KB