結果
問題 | No.1637 Easy Tree Query |
ユーザー |
![]() |
提出日時 | 2024-06-30 18:27:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 441 ms / 2,000 ms |
コード長 | 462 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,108 KB |
実行使用メモリ | 97,056 KB |
最終ジャッジ日時 | 2024-06-30 18:28:11 |
合計ジャッジ時間 | 13,326 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 33 |
ソースコード
n,Q=map(int,input().split())e=[[] for i in range(n)]for i in range(n-1):a,b=map(int,input().split())a-=1b-=1e[a]+=[b]e[b]+=[a]v=[0]*nu=[0]*np=[0]*nq=[0]while len(q)>0:s=q[-1]if v[s]==0:v[s]=1for t in e[s]:if t!=p[s]:q+=[t]p[t]=selse:u[s]=1for t in e[s]:if t!=p[s]:u[s]+=u[t]q.pop()g=0for i in range(Q):p,x=map(int,input().split())p-=1g+=u[p]*xprint(g)