結果

問題 No.1637 Easy Tree Query
ユーザー face4face4
提出日時 2021-08-06 22:17:32
言語 Kotlin
(1.9.23)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 739 bytes
コンパイル時間 14,227 ms
コンパイル使用メモリ 442,796 KB
実行使用メモリ 80,720 KB
最終ジャッジ日時 2023-10-17 05:13:45
合計ジャッジ時間 47,309 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 255 ms
54,416 KB
testcase_01 AC 255 ms
54,412 KB
testcase_02 AC 1,179 ms
80,720 KB
testcase_03 AC 267 ms
53,248 KB
testcase_04 AC 637 ms
65,516 KB
testcase_05 AC 1,071 ms
67,264 KB
testcase_06 AC 902 ms
68,144 KB
testcase_07 AC 665 ms
61,000 KB
testcase_08 AC 580 ms
63,764 KB
testcase_09 AC 893 ms
71,652 KB
testcase_10 AC 745 ms
64,072 KB
testcase_11 AC 1,039 ms
73,892 KB
testcase_12 AC 1,114 ms
76,164 KB
testcase_13 AC 588 ms
61,628 KB
testcase_14 AC 756 ms
69,180 KB
testcase_15 AC 1,052 ms
78,028 KB
testcase_16 AC 962 ms
75,024 KB
testcase_17 AC 656 ms
62,576 KB
testcase_18 AC 1,129 ms
68,960 KB
testcase_19 AC 983 ms
67,552 KB
testcase_20 AC 1,253 ms
71,856 KB
testcase_21 AC 800 ms
66,604 KB
testcase_22 AC 1,041 ms
74,440 KB
testcase_23 AC 705 ms
62,960 KB
testcase_24 AC 748 ms
67,900 KB
testcase_25 AC 1,008 ms
67,980 KB
testcase_26 AC 1,107 ms
76,680 KB
testcase_27 AC 1,116 ms
74,052 KB
testcase_28 AC 885 ms
67,056 KB
testcase_29 AC 995 ms
69,720 KB
testcase_30 AC 596 ms
65,892 KB
testcase_31 AC 888 ms
63,008 KB
testcase_32 AC 795 ms
67,520 KB
testcase_33 AC 1,091 ms
66,260 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

// recursion limit error が怖い
fun main() {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val v = List(n) { mutableListOf<Int>() }
    repeat(n - 1) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() - 1 }
        v[a].add(b)
        v[b].add(a)
    }

    val subsiz = MutableList(n) { 0 }
    subsiz[0] = n

    fun dfs(now: Int) {
        subsiz[now] = 1
        for (next in v[now]) {
            if (subsiz[next] == 0) {
                dfs(next)
                subsiz[now] += subsiz[next]
            }
        }
    }

    dfs(0)

    var ans = 0L
    repeat(q) {
        val (p, x) = readLine()!!.split(" ").map { it.toInt() }
        ans += subsiz[p-1].toLong() * x
        println(ans)
    }
}
0