Submission #7064124


Source Code Expand

Copy
#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, Q;
vector<ll> edges[300100];
ll c[300100];

void dfs(ll ix, ll carry, ll par) {
  c[ix] += carry;
  for (auto nx : edges[ix]) {
    if (nx == par)
      continue;
    dfs(nx, c[ix], ix);
  }
}

signed main() {
  cin>>N>>Q;
  rep(i,N-1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  rep(i,Q) {
    ll p, x;
    cin >> p >> x;
    p--;
    c[p] += x;
  }
  dfs(0, 0, -1);
  rep(i,N) {
    cout << c[i];
    if (i == N-1)
      cout << endl;
    else
      cout << " ";
  }
  return 0;
}

Submission Info

Submission Time
Task D - Ki
User bobuhiro11
Language C++14 (GCC 5.4.1)
Score 400
Code Size 828 Byte
Status
Exec Time 376 ms
Memory 26880 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 a01, a02
All 400 / 400 a01, a02, b03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14
after_contest 0 / 0 after_contest_15, after_contest_16, after_contest_17
Case Name Status Exec Time Memory
a01 3 ms 7552 KB
a02 3 ms 7552 KB
after_contest_15 3 ms 7552 KB
after_contest_16 358 ms 26752 KB
after_contest_17 360 ms 17792 KB
b03 4 ms 7552 KB
b04 364 ms 26752 KB
b05 342 ms 26880 KB
b06 288 ms 17904 KB
b07 262 ms 19440 KB
b08 354 ms 22772 KB
b09 362 ms 18944 KB
b10 355 ms 24704 KB
b11 374 ms 22016 KB
b12 376 ms 20352 KB
b13 375 ms 25216 KB
b14 304 ms 17904 KB