結果
| 問題 |
No.1637 Easy Tree Query
|
| コンテスト | |
| ユーザー |
wgrape
|
| 提出日時 | 2023-11-01 15:05:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 496 bytes |
| コンパイル時間 | 506 ms |
| コンパイル使用メモリ | 82,248 KB |
| 実行使用メモリ | 92,544 KB |
| 最終ジャッジ日時 | 2024-09-25 17:58:02 |
| 合計ジャッジ時間 | 15,210 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 RE * 1 |
ソースコード
N,Q = map(int,input().split())
G = [[] for i in range(N)]
for _ in range(N - 1):
a,b = map(int,input().split())
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
cnt = [0] * N # 自分を含む子の数
def dfs(v, p):
c = 1
for child in G[v]:
if child == p:
continue
c += dfs(child, v)
cnt[v] = c
return c
dfs(0, -1)
ans = 0
for _ in range(Q):
p,x = map(int,input().split())
ans += cnt[p - 1] * x
print(ans)
wgrape