Submission #7000087


Source Code Expand

Copy
<?php
fscanf(STDIN, '%d %d', $n, $q);
for ($i  = 0; $i < $n - 1; $i++) {
    fscanf(STDIN, '%d %d', $a, $b);
    $a--;
    $b--;
    $g[$a][] = $b;
}
$r = array_fill(0, $n, 0);
for ($i  = 0; $i < $q; $i++) {
    fscanf(STDIN, '%d %d', $p, $x);
    $r[$p - 1] += $x;
}
$point = array_fill(0, $n, 0);
dfs($g, 0, 0, $r, $point);
$ans = implode(' ', $point);
echo $ans . PHP_EOL;

function dfs($g, $v = 0, $x = 0, $r, &$point) {
    if (isset($r[$v])) $x += $r[$v];
    $point[$v] += $x;

    if (!isset($g[$v])) return;
    foreach ($g[$v] as $next_v) {
        dfs($g, $next_v, $x, $r, $point);
    }
}

Submission Info

Submission Time
Task D - Ki
User hideyuk1
Language PHP7 (7.0.15)
Score 400
Code Size 626 Byte
Status AC
Exec Time 332 ms
Memory 176632 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 9 ms 4604 KB
a02 AC 9 ms 4604 KB
b03 AC 9 ms 4604 KB
b04 AC 332 ms 176632 KB
b05 AC 324 ms 176632 KB
b06 AC 232 ms 32372 KB
b07 AC 222 ms 35260 KB
b08 AC 283 ms 102900 KB
b09 AC 272 ms 65216 KB
b10 AC 320 ms 131576 KB
b11 AC 315 ms 107000 KB
b12 AC 302 ms 90616 KB
b13 AC 318 ms 176632 KB
b14 AC 226 ms 32372 KB