結果

問題 No.1637 Easy Tree Query
ユーザー moharan627moharan627
提出日時 2021-08-06 21:31:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 421 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 12,044 KB
実行使用メモリ 46,108 KB
最終ジャッジ日時 2023-10-17 04:58:15
合計ジャッジ時間 10,749 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,004 KB
testcase_01 AC 29 ms
10,004 KB
testcase_02 AC 386 ms
28,040 KB
testcase_03 AC 28 ms
10,004 KB
testcase_04 AC 153 ms
19,324 KB
testcase_05 AC 277 ms
16,724 KB
testcase_06 AC 191 ms
14,992 KB
testcase_07 AC 99 ms
10,464 KB
testcase_08 AC 125 ms
17,228 KB
testcase_09 AC 303 ms
23,652 KB
testcase_10 AC 146 ms
14,076 KB
testcase_11 AC 372 ms
25,276 KB
testcase_12 AC 326 ms
21,824 KB
testcase_13 AC 92 ms
14,164 KB
testcase_14 AC 227 ms
24,040 KB
testcase_15 AC 354 ms
25,788 KB
testcase_16 AC 335 ms
27,508 KB
testcase_17 AC 115 ms
14,160 KB
testcase_18 AC 265 ms
16,716 KB
testcase_19 AC 269 ms
18,040 KB
testcase_20 AC 343 ms
21,428 KB
testcase_21 AC 212 ms
19,680 KB
testcase_22 AC 413 ms
27,904 KB
testcase_23 AC 121 ms
15,060 KB
testcase_24 AC 194 ms
19,704 KB
testcase_25 AC 276 ms
16,252 KB
testcase_26 AC 353 ms
22,340 KB
testcase_27 AC 421 ms
27,076 KB
testcase_28 AC 216 ms
15,820 KB
testcase_29 AC 293 ms
20,948 KB
testcase_30 AC 168 ms
20,644 KB
testcase_31 AC 192 ms
10,124 KB
testcase_32 AC 162 ms
16,336 KB
testcase_33 AC 248 ms
14,112 KB
testcase_34 AC 234 ms
46,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = float('inf')
#10**20,2**63,float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
#from collections import defaultdict
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LC(): return list(input())
def IC(): return [int(c) for c in input()]
def MI(): return map(int, sys.stdin.readline().split())
N,Q = MI()
Graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    A,B = MI()
    Graph[A].append(B)
    Graph[B].append(A)
sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!
DP = [0]*(N+1)
Seen = [False]*(N+1)
def dfs(now):
    Seen[now] = True
    DP[now] = 1
    #→nowで初めてたどり着いたときに行う処理はここで
    for next in Graph[now]:
        if not Seen[next]:
            dfs(next)
            DP[now] += DP[next]
            # next→now:戻る時に行う処理はここで
    # now←で全ての探索可ノードを終えたときに行う処理はここで
dfs(1)#根は1
#print(DP)
Ans = 0
for _ in range(Q):
    P,X = MI()
    Ans += DP[P]*X
    print(Ans)
0