結果
問題 |
No.1637 Easy Tree Query
|
ユーザー |
![]() |
提出日時 | 2021-08-06 23:07:40 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 616 bytes |
コンパイル時間 | 118 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 52,608 KB |
最終ジャッジ日時 | 2024-09-17 03:21:17 |
合計ジャッジ時間 | 14,368 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 32 WA * 1 |
ソースコード
import sys input = sys.stdin.readline sys.setrecursionlimit(10**8) N,Q = map(int,input().split()) AB = [tuple(map(int,input().split())) for i in range(N-1)] PX = [tuple(map(int,input().split())) for i in range(Q)] es = [[] for _ in range(N)] for a,b in AB: a,b = a-1,b-1 es[a].append(b) es[b].append(a) cs = [0] * N def dfs(v,p=-1): if len(es[v])==1: cs[v] = 2 if v==0 else 1 return cs[v] ret = 1 for to in es[v]: if to==p: continue ret += dfs(to,v) cs[v] = ret return ret dfs(0) ans = 0 for p,x in PX: p -= 1 ans += cs[p] * x print(ans)