結果

問題 No.1637 Easy Tree Query
ユーザー 河野竜也河野竜也
提出日時 2021-08-24 23:57:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 354 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 28,544 KB
最終ジャッジ日時 2024-04-27 12:07:38
合計ジャッジ時間 24,755 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 1,085 ms
28,032 KB
testcase_03 AC 30 ms
10,880 KB
testcase_04 AC 350 ms
19,840 KB
testcase_05 AC 832 ms
17,280 KB
testcase_06 AC 558 ms
15,616 KB
testcase_07 AC 283 ms
11,136 KB
testcase_08 AC 285 ms
17,920 KB
testcase_09 AC 741 ms
23,936 KB
testcase_10 AC 399 ms
14,592 KB
testcase_11 AC 1,033 ms
25,472 KB
testcase_12 AC 942 ms
22,016 KB
testcase_13 AC 197 ms
14,848 KB
testcase_14 AC 563 ms
24,320 KB
testcase_15 AC 972 ms
25,984 KB
testcase_16 AC 805 ms
27,648 KB
testcase_17 AC 289 ms
14,848 KB
testcase_18 AC 784 ms
17,280 KB
testcase_19 AC 788 ms
18,560 KB
testcase_20 AC 995 ms
21,760 KB
testcase_21 AC 552 ms
20,096 KB
testcase_22 AC 1,121 ms
28,032 KB
testcase_23 AC 293 ms
15,744 KB
testcase_24 AC 482 ms
20,096 KB
testcase_25 AC 851 ms
16,768 KB
testcase_26 AC 1,020 ms
22,784 KB
testcase_27 AC 1,203 ms
27,264 KB
testcase_28 AC 623 ms
16,384 KB
testcase_29 AC 787 ms
21,248 KB
testcase_30 AC 355 ms
21,120 KB
testcase_31 AC 603 ms
10,880 KB
testcase_32 AC 427 ms
16,896 KB
testcase_33 AC 777 ms
14,720 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(x,p):
  cnt=1
  for i in g[x]:
    if i!=p:
      cnt+=dfs(i,x)
    ans[x]=cnt
  return cnt
n,q=map(int,input().split())
g=[[] for i in range(n+1)]
for i in range(n-1):
  a,b=map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
ans=[0]*(n+1)
dfs(0,-1)
a=0
for i in range(q):
  p,x=map(int,input().split())
  a+=ans[p-1]*x
  print(a)
0