Submission #6994576


Source Code Expand

Copy
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

V<int> G[200010];
ll X[200010] = {};
ll A[200010] = {};

void dfs(int par, int node, ll x) {
    A[node] = x + X[node];
    for (int v : G[node]) {
        if (v == par) continue;
        dfs(node, v, x + X[node]);
    }
}

int main() {
    int n, q; cin >> n >> q;
    loop (n - 1, i) {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    loop (q, i) {
        int p, x; cin >> p >> x;
        X[p] += x;
    }
    dfs(-1, 1, 0);

    loop (n - 1, i) {
        cout << A[i + 1] << " ";
    }
    cout << A[n] << endl;

    return 0;
}

Submission Info

Submission Time
Task D - Ki
User na_o_s
Language C++14 (GCC 5.4.1)
Score 400
Code Size 921 Byte
Status AC
Exec Time 363 ms
Memory 28672 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 3 ms 6016 KB
a02 AC 3 ms 6016 KB
b03 AC 3 ms 6016 KB
b04 AC 362 ms 28672 KB
b05 AC 325 ms 28416 KB
b06 AC 289 ms 16116 KB
b07 AC 252 ms 16628 KB
b08 AC 343 ms 22904 KB
b09 AC 347 ms 15488 KB
b10 AC 349 ms 24576 KB
b11 AC 353 ms 21248 KB
b12 AC 344 ms 18944 KB
b13 AC 363 ms 26752 KB
b14 AC 297 ms 15988 KB