Submission #7014727


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, Q;
vector<int> E[201010];
int val[201010];
//---------------------------------------------------------------------------------------------------
void dfs(int cu, int pa = -1) {
	fore(to, E[cu]) if(pa != to) {
		val[to] += val[cu];
		dfs(to, cu);
	}
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> Q;
	rep(i, 0, N - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}

	rep(q, 0, Q) {
		int p, x; cin >> p >> x;
		p--;
		val[p] += x;
	}

	dfs(0);

	rep(i, 0, N) {
		if (i) printf(" ");
		printf("%d", val[i]);
	}
	printf("\n");
}





Submission Info

Submission Time
Task D - Ki
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1977 Byte
Status AC
Exec Time 130 ms
Memory 23552 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 3 ms 4992 KB
a02 AC 3 ms 4992 KB
after_contest_15 AC 3 ms 4992 KB
after_contest_16 AC 130 ms 23296 KB
after_contest_17 AC 125 ms 13440 KB
b03 AC 3 ms 4992 KB
b04 AC 128 ms 23296 KB
b05 AC 125 ms 23552 KB
b06 AC 99 ms 13812 KB
b07 AC 97 ms 14708 KB
b08 AC 118 ms 19064 KB
b09 AC 121 ms 13184 KB
b10 AC 127 ms 20224 KB
b11 AC 126 ms 17664 KB
b12 AC 125 ms 16000 KB
b13 AC 126 ms 21760 KB
b14 AC 100 ms 13684 KB