結果

問題 No.1637 Easy Tree Query
ユーザー roarisroaris
提出日時 2021-08-06 21:23:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 517 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 166,628 KB
最終ジャッジ日時 2023-10-17 04:40:20
合計ジャッジ時間 7,046 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
55,604 KB
testcase_01 AC 33 ms
55,604 KB
testcase_02 AC 137 ms
88,168 KB
testcase_03 AC 35 ms
55,604 KB
testcase_04 AC 109 ms
82,524 KB
testcase_05 AC 117 ms
80,892 KB
testcase_06 AC 98 ms
79,656 KB
testcase_07 AC 75 ms
76,448 KB
testcase_08 AC 92 ms
81,220 KB
testcase_09 AC 135 ms
85,572 KB
testcase_10 AC 88 ms
78,928 KB
testcase_11 AC 178 ms
86,620 KB
testcase_12 AC 150 ms
84,300 KB
testcase_13 AC 80 ms
79,248 KB
testcase_14 AC 130 ms
85,812 KB
testcase_15 AC 157 ms
87,032 KB
testcase_16 AC 153 ms
88,212 KB
testcase_17 AC 83 ms
79,076 KB
testcase_18 AC 116 ms
80,828 KB
testcase_19 AC 115 ms
81,748 KB
testcase_20 AC 138 ms
84,132 KB
testcase_21 AC 115 ms
82,772 KB
testcase_22 AC 165 ms
88,436 KB
testcase_23 AC 87 ms
79,668 KB
testcase_24 AC 105 ms
82,796 KB
testcase_25 AC 117 ms
80,476 KB
testcase_26 AC 141 ms
84,688 KB
testcase_27 AC 168 ms
87,936 KB
testcase_28 AC 104 ms
80,144 KB
testcase_29 AC 129 ms
83,612 KB
testcase_30 AC 105 ms
83,468 KB
testcase_31 AC 80 ms
76,108 KB
testcase_32 AC 95 ms
80,564 KB
testcase_33 AC 105 ms
79,016 KB
testcase_34 AC 200 ms
166,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5+10)
from collections import *

def dfs(v, pv=-1):
    for nv in G[v]:
        if nv==pv:
            continue
        
        dfs(nv, v)
        num[v] += num[nv]

N, Q = map(int, input().split())
G = [[] 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)

num = [1]*N
dfs(0)
ans = 0

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