Contest Duration: - (local time) (100 minutes) Back to Home

Submission #6990972

Source Code Expand

Copy
```#include "bits/stdc++.h"
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, Q;
vector<vector<int>> tree;
vector<ll> ans;

void dfs(int v, int p, ll sum) {
ans[v] = sum;

for (int u : tree[v]) {
if (u != p) {
dfs(u, v, sum);
}
}
}

int main() {
cin >> N >> Q;
tree.resize(N);
rep(i, N - 1) {
int a, b;
cin >> a >> b;
a--; b--;

tree[a].push_back(b);
tree[b].push_back(a);
}

rep(i, Q) {
int p, x;
cin >> p >> x;

add[p - 1] += x;
}

ans.resize(N);
dfs(0, -1, 0);

rep(i, N) {
cout << ans[i] << (i == N - 1 ? '\n' : ' ');
}
}```

#### Submission Info

Submission Time 2019-08-18 21:13:23+0900 D - Ki myun C++14 (GCC 5.4.1) 400 1612 Byte AC 140 ms 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 1 ms 256 KB
a02 AC 1 ms 256 KB
b03 AC 1 ms 256 KB
b04 AC 140 ms 25600 KB
b05 AC 132 ms 25856 KB
b06 AC 104 ms 16116 KB
b07 AC 99 ms 17012 KB
b08 AC 116 ms 21368 KB
b09 AC 121 ms 15488 KB
b10 AC 137 ms 22528 KB
b11 AC 126 ms 19968 KB
b12 AC 128 ms 18304 KB
b13 AC 131 ms 24064 KB
b14 AC 99 ms 16116 KB