結果
問題 | No.1637 Easy Tree Query |
ユーザー | MasKoaTS |
提出日時 | 2021-10-03 18:19:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 505 ms / 2,000 ms |
コード長 | 1,078 bytes |
コンパイル時間 | 302 ms |
コンパイル使用メモリ | 87,332 KB |
実行使用メモリ | 186,652 KB |
最終ジャッジ日時 | 2023-09-28 18:38:57 |
合計ジャッジ時間 | 19,167 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 228 ms
83,416 KB |
testcase_01 | AC | 224 ms
83,448 KB |
testcase_02 | AC | 404 ms
109,632 KB |
testcase_03 | AC | 223 ms
83,416 KB |
testcase_04 | AC | 338 ms
93,172 KB |
testcase_05 | AC | 388 ms
100,540 KB |
testcase_06 | AC | 339 ms
95,040 KB |
testcase_07 | AC | 288 ms
89,624 KB |
testcase_08 | AC | 320 ms
91,016 KB |
testcase_09 | AC | 431 ms
100,600 KB |
testcase_10 | AC | 325 ms
92,396 KB |
testcase_11 | AC | 468 ms
105,276 KB |
testcase_12 | AC | 441 ms
103,756 KB |
testcase_13 | AC | 307 ms
89,040 KB |
testcase_14 | AC | 393 ms
98,256 KB |
testcase_15 | AC | 456 ms
104,908 KB |
testcase_16 | AC | 446 ms
102,732 KB |
testcase_17 | AC | 304 ms
90,564 KB |
testcase_18 | AC | 371 ms
99,820 KB |
testcase_19 | AC | 382 ms
100,324 KB |
testcase_20 | AC | 446 ms
104,356 KB |
testcase_21 | AC | 359 ms
95,612 KB |
testcase_22 | AC | 483 ms
107,508 KB |
testcase_23 | AC | 313 ms
90,568 KB |
testcase_24 | AC | 355 ms
95,572 KB |
testcase_25 | AC | 378 ms
100,508 KB |
testcase_26 | AC | 442 ms
104,900 KB |
testcase_27 | AC | 505 ms
108,900 KB |
testcase_28 | AC | 361 ms
96,776 KB |
testcase_29 | AC | 409 ms
101,592 KB |
testcase_30 | AC | 350 ms
93,764 KB |
testcase_31 | AC | 314 ms
95,064 KB |
testcase_32 | AC | 333 ms
92,988 KB |
testcase_33 | AC | 361 ms
98,928 KB |
testcase_34 | AC | 424 ms
186,652 KB |
ソースコード
import itertools as iter import collections as coll import heapq as hq import bisect as bis from decimal import Decimal as dec from copy import deepcopy as dcopy import math import sys sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def getN(): return int(sys.stdin.readline().rstrip()) def getNs(): return map(int,sys.stdin.readline().rstrip().split()) def getList(): return list(map(int,sys.stdin.readline().rstrip().split())) def strinps(n): return [sys.stdin.readline().rstrip() for _ in range(n)] pi = 3.141592653589793 mod = 10**9+7 MOD = 998244353 INF = math.inf dx = [1,0,-1,0]; dy = [0,1,0,-1] """ Main Code """ n,q = getNs() route = [[] for _ in [0]*n] for _ in [0]*(n-1): a,b = getNs() a -= 1; b -= 1 route[a].append(b) route[b].append(a) visited = [False]*n cnt = [0]*n def dfs(v): res = 1 for nv in route[v]: if not(visited[nv]): visited[nv] = True res += dfs(nv) cnt[v] = res return res visited[0] = True dfs(0) ans = 0 query = [getList() for _ in [0]*q] for p,x in query: ans += x*cnt[p-1] print(ans)