結果
| 問題 |
No.1637 Easy Tree Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-06 23:49:31 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 715 bytes |
| コンパイル時間 | 95 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 49,664 KB |
| 最終ジャッジ日時 | 2024-09-17 04:21:21 |
| 合計ジャッジ時間 | 12,591 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 33 |
ソースコード
def countup(now, R, used, count):
# if len(root[now]) == 1 and root[now][0] in used:
# count[root[now][0]] += count[now]+1
# return
if now in used:
return
for next_ in root[now]:
if next_ == R:
continue
countup(next_, now, used | set([now]), count)
if now == R:
return
count[R] += count[now]
N, Q = map(int, input().split())
root = [[] for i in range(N+1)]
for i in range(N-1):
a, b = map(int, input().split())
root[a-1].append(b-1)
root[b-1].append(a-1)
count = [1]*N
countup(0, 0, set(), count)
ans = 0
for i in range(Q):
p, x = map(int, input().split())
cost[p-1] += x
ans += count[p-1]*x
print(ans)