Submission #6995234


Source Code Expand

Copy
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int N, Q;
int a[200005], b[200005], p[200005];
long long int x[200005];
vector<int>Adj[200005];

int par[200005];
int used[200005];

long long int val[200005];

void DFS(int k) {

	used[k] = 1;

	for (auto y: Adj[k]) {
		if (used[y] == 0) { par[y] = k; val[y] += val[k]; DFS(y); }
	}
}


int main(void) {
	cin >> N >> Q;

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



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

	DFS(1);

	for (int i = 1; i <= N; i++) {
		if (i != 1) { cout << " "; }
		cout << val[i];
	}cout << endl;

	return 0;
}

Submission Info

Submission Time
Task D - Ki
User LEE_0102
Language C++14 (GCC 5.4.1)
Score 400
Code Size 796 Byte
Status AC
Exec Time 359 ms
Memory 29696 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 8448 KB
a02 AC 3 ms 8448 KB
b03 AC 3 ms 8448 KB
b04 AC 358 ms 29568 KB
b05 AC 336 ms 29696 KB
b06 AC 303 ms 19956 KB
b07 AC 243 ms 20980 KB
b08 AC 349 ms 25208 KB
b09 AC 342 ms 19456 KB
b10 AC 345 ms 26368 KB
b11 AC 358 ms 23808 KB
b12 AC 359 ms 22144 KB
b13 AC 353 ms 28032 KB
b14 AC 287 ms 19956 KB