結果
| 問題 | No.1637 Easy Tree Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-06 21:31:52 |
| 言語 | Python3 (3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 769 ms / 2,000 ms |
| + 584µs | |
| コード長 | 437 bytes |
| 記録 | |
| コンパイル時間 | 295 ms |
| コンパイル使用メモリ | 21,284 KB |
| 実行使用メモリ | 51,704 KB |
| 最終ジャッジ日時 | 2026-08-29 06:24:48 |
| 合計ジャッジ時間 | 19,226 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 |
ソースコード
import sys sys.setrecursionlimit(10**6) n,q=map(int,input().split()) node=[[]for i in range(n)] for i in range(n-1): a,b=map(int,input().split()) node[a-1].append(b-1) node[b-1].append(a-1) cnt=[0]*n visited=[0]*n visited[0]=1 def dfs(x): now=1 for y in node[x]: if visited[y]==0: visited[y]=1 now+=dfs(y) cnt[x]=now return now dfs(0) ans=0 for i in range(q): p,x=map(int,input().split()) ans+=cnt[p-1]*x print(ans)