結果

問題 No.1637 Easy Tree Query
ユーザー tcltktcltk
提出日時 2021-10-17 06:02:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 823 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,592 KB
実行使用メモリ 176,908 KB
最終ジャッジ日時 2023-10-17 22:23:40
合計ジャッジ時間 11,876 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
85,892 KB
testcase_01 AC 130 ms
85,892 KB
testcase_02 AC 264 ms
100,068 KB
testcase_03 AC 135 ms
85,944 KB
testcase_04 AC 241 ms
94,276 KB
testcase_05 AC 252 ms
92,612 KB
testcase_06 AC 218 ms
91,712 KB
testcase_07 AC 187 ms
89,040 KB
testcase_08 AC 223 ms
92,904 KB
testcase_09 AC 304 ms
97,300 KB
testcase_10 AC 205 ms
91,060 KB
testcase_11 AC 315 ms
98,328 KB
testcase_12 AC 304 ms
96,172 KB
testcase_13 AC 191 ms
91,228 KB
testcase_14 AC 284 ms
97,532 KB
testcase_15 AC 321 ms
98,720 KB
testcase_16 AC 328 ms
99,800 KB
testcase_17 AC 200 ms
91,204 KB
testcase_18 AC 241 ms
92,576 KB
testcase_19 AC 257 ms
93,516 KB
testcase_20 AC 289 ms
95,748 KB
testcase_21 AC 254 ms
94,500 KB
testcase_22 AC 347 ms
100,028 KB
testcase_23 AC 200 ms
92,020 KB
testcase_24 AC 244 ms
94,504 KB
testcase_25 AC 246 ms
92,616 KB
testcase_26 AC 300 ms
96,456 KB
testcase_27 AC 353 ms
99,556 KB
testcase_28 AC 231 ms
92,232 KB
testcase_29 AC 269 ms
95,340 KB
testcase_30 AC 244 ms
95,200 KB
testcase_31 AC 187 ms
88,728 KB
testcase_32 AC 222 ms
92,640 KB
testcase_33 AC 224 ms
91,152 KB
testcase_34 AC 325 ms
176,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


sys.setrecursionlimit(1000000)

# _INPUT = """3 1
# 1 2
# 1 3
# 1 5

# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

def dfs(G, count, parent, p):
    v = 1
    for p1 in G[p]:
        if p1 == parent:
            continue
        v += dfs(G, count, p, p1)
    count[p] = v
    return v

N, Q = map(int, input().split())
G = [list() for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

count = [0] * N
dfs(G, count, -1, 0)

n = 0
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    n += count[p] * x
    print(n)

0