結果
問題 |
No.1637 Easy Tree Query
|
ユーザー |
![]() |
提出日時 | 2021-08-07 07:42:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 413 ms / 2,000 ms |
コード長 | 491 bytes |
コンパイル時間 | 227 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 176,660 KB |
最終ジャッジ日時 | 2024-09-17 11:24:50 |
合計ジャッジ時間 | 12,336 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 33 |
ソースコード
import sys sys.setrecursionlimit(10 ** 6) n,q = map(int,input().split()) l = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) l[a-1].append(b-1) l[b-1].append(a-1) ans = 0 ne = [1] + [0] * (n - 1) def dfs(node): res = 1 for nd in l[node]: if ne[nd] == 0: ne[nd] = 1 res += dfs(nd) ne[node] = res return res dfs(0) for _ in range(q): p,x = map(int,input().split()) ans += ne[p-1] * x print(ans)