結果
問題 | No.1637 Easy Tree Query |
ユーザー | McGregorsh |
提出日時 | 2022-07-22 21:08:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 563 ms / 2,000 ms |
コード長 | 1,966 bytes |
コンパイル時間 | 262 ms |
コンパイル使用メモリ | 82,604 KB |
実行使用メモリ | 195,436 KB |
最終ジャッジ日時 | 2024-07-04 05:04:32 |
合計ジャッジ時間 | 17,182 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 131 ms
89,520 KB |
testcase_01 | AC | 137 ms
89,228 KB |
testcase_02 | AC | 524 ms
102,496 KB |
testcase_03 | AC | 134 ms
89,568 KB |
testcase_04 | AC | 275 ms
96,608 KB |
testcase_05 | AC | 437 ms
94,688 KB |
testcase_06 | AC | 340 ms
94,244 KB |
testcase_07 | AC | 262 ms
91,072 KB |
testcase_08 | AC | 249 ms
94,788 KB |
testcase_09 | AC | 409 ms
100,180 KB |
testcase_10 | AC | 318 ms
92,892 KB |
testcase_11 | AC | 460 ms
100,380 KB |
testcase_12 | AC | 481 ms
98,116 KB |
testcase_13 | AC | 236 ms
93,080 KB |
testcase_14 | AC | 343 ms
99,896 KB |
testcase_15 | AC | 453 ms
101,352 KB |
testcase_16 | AC | 395 ms
102,448 KB |
testcase_17 | AC | 264 ms
92,684 KB |
testcase_18 | AC | 424 ms
94,784 KB |
testcase_19 | AC | 413 ms
96,020 KB |
testcase_20 | AC | 480 ms
98,068 KB |
testcase_21 | AC | 330 ms
96,744 KB |
testcase_22 | AC | 492 ms
102,740 KB |
testcase_23 | AC | 254 ms
93,936 KB |
testcase_24 | AC | 313 ms
96,872 KB |
testcase_25 | AC | 431 ms
94,008 KB |
testcase_26 | AC | 479 ms
98,536 KB |
testcase_27 | AC | 563 ms
102,256 KB |
testcase_28 | AC | 381 ms
94,380 KB |
testcase_29 | AC | 423 ms
97,736 KB |
testcase_30 | AC | 272 ms
97,880 KB |
testcase_31 | AC | 355 ms
90,904 KB |
testcase_32 | AC | 304 ms
94,792 KB |
testcase_33 | AC | 411 ms
92,836 KB |
testcase_34 | AC | 390 ms
195,436 KB |
ソースコード
import sys, re from fractions import Fraction from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement, permutations from bisect import bisect, bisect_left, bisect_right from functools import reduce from decimal import Decimal, getcontext def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def lcm(a, b): return a * b // gcd(a, b) def get_distance(x1, y1, x2, y2): d = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) return d def rotate(table): n_fild = [] for x in zip(*table[::-1]): n_fild.append(x) return n_fild sys.setrecursionlimit(10 ** 7) INF = float('inf') MOD = 10 ** 9 + 7 MOD2 = 998244353 ###関数コピーしたか?### def main(): n, q = i_map() nums = [[] for i in range(n)] for i in range(n-1): a, b = i_map() a -= 1 b -= 1 nums[a].append(b) nums[b].append(a) def dfs(s, p, juge): juge[s] = True cou = 1 for i in nums[s]: if i == p: continue if juge[i] == False: cou += dfs(i, s, juge) count[s] = cou return cou count = [0] * n juge = [False] * n dfs(0, -1, juge) ans = 0 for i in range(q): point, cost = i_map() point -= 1 ans += count[point] * cost print(ans) if __name__ == '__main__': main()