Language: C++

import java.lang.Math.sqrt
import java.util.*

const val MOD = 1000000007L
const val INF = Long.MAX_VALUE - 1

fun main(args: Array<String>) {
    val (n, q) = readIntList()


    val edges = Array(n) {
        return@Array Edge(it)
    }

    (n - 1).rep {
        val (a, b) = readIntList()
        edges[a - 1].nexts.add(b - 1)
    }

    q.rep {
        val (p, x) = readIntList()
        edges[p - 1].count += x
    }

    val ans = Array(n) {
        return@Array 0L
    }

    fun dfs(n: Int, ret: Long) {
        val now = ret + edges[n].count
        ans[n] = now

        edges[n].nexts.forEach {
            dfs(it, now)
        }
    }

    dfs(0, 0)

    ans.forEach {
        print(it)
        print(" ")
    }
}

class Edge(var num: Int) {
    var count = 0
    val nexts = emptyList<Int>().toMutableList()
}


fun readList() = readLine()!!.split(' ')
fun readInt() = readIntList().first()
fun readIntList() = readList().map(String::toInt)
fun readLong() = readLongList().first()
fun readLongList() = readList().map(String::toLong)
fun readDoubleList() = readList().map(String::toDouble)

fun <T> readClass(n: Int, body: (List<String>) -> T): List<T> {
    val ret = mutableListOf<T>()
    for (i in 0 until n) {
        ret.add(body(readList()))
    }
    return ret
}

fun readPair(): Pair<String, String> {
    val splite = readLine()!!.split(' ')
    return Pair(splite[0], splite[1])
}

fun <T> List<T>.copy() = this.map { it }

fun Long.toBinaryString(): String {
    var t = this
    var res = ""
    while (t > 0) {
        res += (t % 2).toString()
        t /= 2
    }
    return res
}

inline fun <reified T> dualArray(h: Int, w: Int, init: (Int, Int) -> T) {
    Array(h) { i ->
        return@Array Array(w) { j ->
            return@Array init(i, j)
        }
    }
}

// 速度のためforEachは避ける
inline fun Int.rep(start: Int = 0, shiftLast: Boolean = false, body: (Int) -> Unit) {
    for (i in start until if (shiftLast) this + start else this) {
        body(i)
    }
}

inline fun Long.rep(start: Long = 0, shiftLast: Boolean = false, body: (Long) -> Unit) {
    for (i in start until if (shiftLast) this + start else this) {
        body(i)
    }
}

// 約数のList
fun divisor(value: Long): List<Long> {
    val max = sqrt(value.toDouble()).toLong()
    val former = mutableListOf<Long>()
    val latter = mutableListOf<Long>()
    (1..max).filter { value % it == 0L }
        .forEach {
            former.add(it)
            latter.add(value / it)
        }
    former.addAll(latter.reversed())
    return former
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from: Long, to: Long = from): List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j -> i % j != 0L }
    }
}

// 素因数分解
fun decom(value: Long): List<Long> {
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a: Long, b: Long): Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base: String, a: String, b: String): String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

// bit全探索
fun bitAllSearch(n: Int, body: (Array<Boolean>) -> Unit) {
    for (bit in 0 until (1 shl n)) {
        val s = Array(n) {
            return@Array false
        }
        for (i in 0 until n) {
            if ((bit and (1 shl i)) shr i == 1) { // i が bit に入るかどうか
                s[i] = true
            }
        }
        body(s)
    }
}

internal class UnionFindTree(size: Int) {

    private val parent = Array(size) {
        return@Array it
    }
    private val rank = Array(size) {
        return@Array 0
    }

    fun union(x: Int, y: Int): Int {
        val xRoot = find(x)
        val yRoot = find(y)

        if (xRoot == yRoot) return xRoot

        when {
            rank[xRoot] > rank[yRoot] -> parent[yRoot] = xRoot
            rank[xRoot] < rank[yRoot] -> parent[xRoot] = yRoot
            xRoot != yRoot -> {
                parent[yRoot] = xRoot
                rank[xRoot]++
            }
        }
        return parent[xRoot]
    }

    fun find(i: Int): Int {
        if (i != parent[i]) {
            parent[i] = find(parent[i])
        }
        return parent[i]
    }

    fun same(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }
}

fun <K, V> Map<K, V>.toMutableMap(): MutableMap<K, V> {
    return HashMap(this)
}

Compiler output:
a.cc:12:15: error: stray '@' in program
   12 |         return@Array Edge(it)
      |               ^
a.cc:26:15: error: stray '@' in program
   26 |         return@Array 0L
      |               ^
a.cc:86:15: error: stray '@' in program
   86 |         return@Array Array(w) { j ->
      |               ^
a.cc:87:19: error: stray '@' in program
   87 |             return@Array init(i, j)
      |                   ^
a.cc:110:6: error: too many decimal points in number
  110 |     (1..max).filter { value % it == 0L }
      |      ^~~~~~
a.cc:124:10: error: too many decimal points in number
  124 |         (2..max).all { j -> i % j != 0L }
      |          ^~~~~~
a.cc:155:19: error: stray '@' in program
  155 |             return@Array false
      |                   ^
a.cc:169:15: error: stray '@' in program
  169 |         return@Array it
      |               ^
a.cc:172:15: error: stray '@' in program
  172 |         return@Array 0
      |               ^
a.cc:1:1: error: 'import' does not name a type
    1 | import java.lang.Math.sqrt
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:46:15: error: expected ')' before 'num'
   46 | class Edge(var num: Int) {
      |           ~   ^~~~
      |               )
a.cc:52:1: error: 'fun' does not name a type
   52 | fun readList() = readLine()!!.split(' ')
      | ^~~
a.cc:67:1: error: 'fun' does not name a type
   67 | fun readPair(): Pair<String, String> {
      | ^~~
a.cc:72:1: error: 'fun' does not name a type
   72 | fun <T> List<T>.copy() = this.map { it }
      | ^~~
a.cc:74:1: error: 'fun' does not name a type
   74 | fun Long.toBinaryString(): String {
      | ^~~
a.cc:84:8: error: 'fun' does not name a type
   84 | inline fun <reified T> dualArray(h: Int, w: Int, init: (Int, Int) -> T) {
      |        ^~~
a.cc:93:8: error: 'fun' does not name a type
   93 | inline fun Int.rep(start: Int = 0, shiftLast: Boolean = false, body: (Int) -> Unit) {
      |        ^~~
a.cc:99:8: error: 'fun' does not name a type
   99 | inline fun Long.rep(start: Long = 0, shiftLast: Boolean = false, body: (Long) -> Unit) {
      |        ^~~
a.cc:106:1: error: 'fun' does not name a type
  106 | fun divisor(value: Long): List<Long> {
      | ^~~
a.cc:121:1: error: 'fun' does not name a type
  121 | fun prime(from: Long, to: Long = from): List<Long> {
      | ^~~
a.cc:129:1: error: 'fun' does not name a type
  129 | fun decom(value: Long): List<Long> {
      | ^~~
a.cc:136:1: error: 'fun' does not name a type
  136 | fun gcd(a: Long, b: Long): Long {
      | ^~~
a.cc:141:1: error: 'fun' does not name a type
  141 | fun swap(base: String, a: String, b: String): String {
      | ^~~
a.cc:152:1: error: 'fun' does not name a type
  152 | fun bitAllSearch(n: Int, body: (Array<Boolean>) -> Unit) {
      | ^~~
a.cc:166:1: error: 'internal' does not name a type
  166 | internal class UnionFindTree(size: Int) {
      | ^~~~~~~~
a.cc:204:1: error: 'fun' does not name a type
  204 | fun <K, V> Map<K, V>.toMutableMap(): MutableMap<K, V> {
      | ^~~