Submission #6994152


Source Code Expand

Copy
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

vector <int> edges[200000];
long long counter[200000];
long long query_op[200000];
bool used[200000];
void dfs(int cur, long long cum_score){
    counter[cur] = query_op[cur] + cum_score;
    used[cur] = true;
    for(int i = 0; i < edges[cur].size(); i++){
        int next = edges[cur][i];
        if(used[next]){
            continue;
        } 
        dfs(next, cum_score + query_op[cur]);
    }
}

int main(){
    int N;
    int Q;
    cin >> N >> Q;
    for(int i  = 0; i < N - 1; i++){
        int a;
        int b;
        cin >> a >> b;
        edges[a - 1].push_back(b - 1);
        edges[b - 1].push_back(a - 1);
    }

    for(int i = 0; i < Q; i++){
        int p;
        int x;
        cin >> p >> x;
        query_op[p - 1] += x;
    }

    dfs(0, 0);

    for(int i = 0; i < N; i++){
        if(i != N - 1){
            cout << counter[i] << " ";
        } else {
            cout << counter[i] << endl;
        }
    }
    return 0;
}

Submission Info

Submission Time
Task D - Ki
User katom
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1251 Byte
Status AC
Exec Time 367 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 3 ms 6272 KB
a02 AC 3 ms 6272 KB
b03 AC 3 ms 6272 KB
b04 AC 355 ms 25856 KB
b05 AC 324 ms 24448 KB
b06 AC 287 ms 16244 KB
b07 AC 253 ms 15732 KB
b08 AC 353 ms 21496 KB
b09 AC 339 ms 15744 KB
b10 AC 356 ms 22656 KB
b11 AC 349 ms 20096 KB
b12 AC 348 ms 18432 KB
b13 AC 367 ms 22656 KB
b14 AC 290 ms 16244 KB