Submission #6992451


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;
int N;
int Q;
vector<int> edge[MAX_N];

int num[MAX_N];

void dfs(int pos = 0, int pre = -1)
{
  for(int next : edge[pos]) {
    if(next == pre) continue;
    num[next] += num[pos];
    dfs(next, pos);
  }
}

signed main()
{
  cin >> N >> Q;
  REP(n,N-1) {
    int a, b; cin >> a >> b; a--; b--;
    edge[a].push_back(b); edge[b].push_back(a);
  }

  REP(q,Q) {
    int p,x;
    cin >> p >> x;
    p--;
    num[p] += x;
  }

  dfs();

  REP(n,N) {
    cout << num[n];
    if(n < N-1) cout << " ";
  }
  cout << endl;

  return 0;
}

Submission Info

Submission Time
Task D - Ki
User takoshi
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1438 Byte
Status AC
Exec Time 305 ms
Memory 24320 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 4992 KB
a02 AC 3 ms 4992 KB
b03 AC 3 ms 4992 KB
b04 AC 287 ms 24064 KB
b05 AC 274 ms 24320 KB
b06 AC 238 ms 15344 KB
b07 AC 214 ms 16240 KB
b08 AC 280 ms 20084 KB
b09 AC 284 ms 16256 KB
b10 AC 289 ms 22016 KB
b11 AC 294 ms 19456 KB
b12 AC 305 ms 17664 KB
b13 AC 304 ms 22528 KB
b14 AC 237 ms 15216 KB