結果
問題 | No.1637 Easy Tree Query |
ユーザー |
|
提出日時 | 2021-12-24 23:33:29 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,189 ms / 2,000 ms |
コード長 | 594 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 51,096 KB |
最終ジャッジ日時 | 2024-09-19 22:51:04 |
合計ジャッジ時間 | 25,828 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 33 |
ソースコード
import sysfrom collections import defaultdictsys.setrecursionlimit(10**6)n, q = map(int, input().split())edge = defaultdict(list)for _ in range(n - 1):a, b = map(int, input().split())a -= 1b -= 1edge[a].append(b)edge[b].append(a)V = [0 for _ in range(n)]def dfs(curr, prev):V[curr] += 1for np in edge[curr]:if np == prev:continuedfs(np, curr)V[curr] += V[np]dfs(0, -1)ans = 0for _ in range(q):p, x = map(int, input().split())p -= 1ans += x * V[p]print(ans)