結果
問題 | No.1637 Easy Tree Query |
ユーザー |
![]() |
提出日時 | 2024-09-25 11:05:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 244 ms / 2,000 ms |
コード長 | 501 bytes |
コンパイル時間 | 228 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 169,848 KB |
最終ジャッジ日時 | 2024-09-25 11:05:48 |
合計ジャッジ時間 | 7,217 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 33 |
ソースコード
import syssys.setrecursionlimit(10**5)input=sys.stdin.readlinen,q=map(int,input().split())graph=[[] for _ in range(n)]for _ in range(n-1):u,v=map(lambda x:int(x)-1,input().split())graph[u].append(v)graph[v].append(u)sub=[0]*ndef sub_calc(v,p):sub[v]=1for nv in graph[v]:if nv==p:continuesub[v]+=sub_calc(nv,v)return sub[v]sub_calc(0,-1)ans=0for _ in range(q):p,x=map(int,input().split())p-=1ans+=x*sub[p]print(ans)