結果

問題 No.1637 Easy Tree Query
ユーザー とりゐとりゐ
提出日時 2021-08-06 22:16:35
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,097 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 81,556 KB
実行使用メモリ 92,304 KB
最終ジャッジ日時 2023-10-17 05:11:22
合計ジャッジ時間 12,947 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,508 KB
testcase_01 AC 41 ms
55,508 KB
testcase_02 AC 427 ms
89,312 KB
testcase_03 AC 41 ms
55,508 KB
testcase_04 AC 206 ms
83,288 KB
testcase_05 AC 378 ms
81,516 KB
testcase_06 AC 285 ms
80,496 KB
testcase_07 AC 198 ms
76,960 KB
testcase_08 AC 178 ms
81,932 KB
testcase_09 AC 334 ms
87,236 KB
testcase_10 AC 231 ms
79,524 KB
testcase_11 AC 430 ms
87,620 KB
testcase_12 AC 414 ms
85,152 KB
testcase_13 AC 163 ms
79,720 KB
testcase_14 AC 272 ms
86,992 KB
testcase_15 AC 406 ms
88,064 KB
testcase_16 AC 354 ms
89,612 KB
testcase_17 AC 192 ms
79,680 KB
testcase_18 AC 359 ms
81,468 KB
testcase_19 AC 354 ms
82,736 KB
testcase_20 AC 427 ms
84,824 KB
testcase_21 AC 271 ms
83,552 KB
testcase_22 AC 459 ms
89,476 KB
testcase_23 AC 191 ms
80,416 KB
testcase_24 AC 242 ms
83,592 KB
testcase_25 AC 379 ms
81,096 KB
testcase_26 AC 427 ms
85,576 KB
testcase_27 AC 489 ms
89,368 KB
testcase_28 AC 303 ms
80,944 KB
testcase_29 AC 353 ms
84,948 KB
testcase_30 AC 202 ms
84,896 KB
testcase_31 AC 296 ms
76,992 KB
testcase_32 AC 233 ms
81,388 KB
testcase_33 AC 356 ms
79,584 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
from collections import deque,Counter
from sys import stdin

#sys.setrecursionlimit(10**7)
int1=lambda x: int(x)-1

inp=lambda :int(input())
mi=lambda :map(int,input().split())
li=lambda :list(mi())
mi1=lambda :map(int1,input().split())
li1=lambda :list(mi1())
mis=lambda :map(str,input().split())
lis=lambda :list(mis())

stinput=lambda :stdin.readline()[:-1]
stinp=lambda :int(stinput())
stmi=lambda :map(int, stdin.readline().split())
stli=lambda :list(stmi())
stmi1=lambda :map(int1, stdin.readline().split())
stli1=lambda :list(stmi1())
stmis=lambda :stdin.readline()[:-1]

pr=print

from collections import defaultdict
"""
#初期値 0
d=defaultdict(int)

#初期値 1
d=defaultdict(lambda:1)
"""

mod=10**9+7
Mod=998244353
INF=10**18
ans=0

n,q=mi()
edge=[[] for i in range(n)]
for i in range(n-1):
  a,b=mi1()
  edge[a].append(b)
  edge[b].append(a)

cnt=[0]*n
seen=[False]*n
def dfs(x):
  seen[x]=True
  tmp=1
  for i in edge[x]:
    if seen[i]==False:
      tmp+=dfs(i)
  cnt[x]=tmp
  return tmp

dfs(0)
for i in range(q):
  p,x=mi()
  ans+=cnt[p-1]*x
  print(ans)
0