結果
問題 | No.1637 Easy Tree Query |
ユーザー | harurun |
提出日時 | 2021-06-18 22:02:35 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 415 ms / 2,000 ms |
コード長 | 1,822 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 12,152 KB |
実行使用メモリ | 63,588 KB |
最終ジャッジ日時 | 2023-10-17 04:33:12 |
合計ジャッジ時間 | 10,154 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
10,376 KB |
testcase_01 | AC | 24 ms
10,376 KB |
testcase_02 | AC | 371 ms
50,920 KB |
testcase_03 | AC | 24 ms
10,376 KB |
testcase_04 | AC | 143 ms
28,056 KB |
testcase_05 | AC | 257 ms
36,264 KB |
testcase_06 | AC | 186 ms
28,008 KB |
testcase_07 | AC | 91 ms
16,808 KB |
testcase_08 | AC | 117 ms
24,476 KB |
testcase_09 | AC | 282 ms
41,992 KB |
testcase_10 | AC | 136 ms
23,304 KB |
testcase_11 | AC | 347 ms
48,884 KB |
testcase_12 | AC | 310 ms
44,004 KB |
testcase_13 | AC | 86 ms
18,960 KB |
testcase_14 | AC | 222 ms
37,800 KB |
testcase_15 | AC | 348 ms
48,456 KB |
testcase_16 | AC | 311 ms
46,664 KB |
testcase_17 | AC | 111 ms
20,996 KB |
testcase_18 | AC | 275 ms
35,032 KB |
testcase_19 | AC | 271 ms
36,572 KB |
testcase_20 | AC | 336 ms
44,556 KB |
testcase_21 | AC | 200 ms
32,848 KB |
testcase_22 | AC | 406 ms
53,812 KB |
testcase_23 | AC | 119 ms
22,288 KB |
testcase_24 | AC | 175 ms
31,176 KB |
testcase_25 | AC | 261 ms
35,692 KB |
testcase_26 | AC | 333 ms
46,268 KB |
testcase_27 | AC | 415 ms
54,888 KB |
testcase_28 | AC | 205 ms
30,208 KB |
testcase_29 | AC | 279 ms
39,848 KB |
testcase_30 | AC | 161 ms
29,720 KB |
testcase_31 | AC | 179 ms
25,060 KB |
testcase_32 | AC | 157 ms
26,708 KB |
testcase_33 | AC | 233 ms
31,780 KB |
testcase_34 | AC | 247 ms
63,588 KB |
ソースコード
class INPUT: def __init__(self): self._l=open(0).read().split() self._length=len(self._l) self._index=0 return def stream(self,k=1,f=int,f2=False): assert(-1<k) if self._length==self._index or self._length-self._index<k: raise Exception("There is no input!") elif f!=str: if k==0: ret=list(map(f,self._l[self._index:])) self._index=self._length return ret if k==1 and not f2: ret=f(self._l[self._index]) self._index+=1 return ret if k==1 and f2: ret=[f(self._l[self._index])] self._index+=1 return ret ret=[] for _ in [0]*k: ret.append(f(self._l[self._index])) self._index+=1 return ret else: if k==0: ret=list(self._l[self._index:]) self._index=self._length return ret if k==1 and not f2: ret=self._l[self._index] self._index+=1 return ret if k==1 and f2: ret=[self._l[self._index]] self._index+=1 return ret ret=[] for _ in [0]*k: ret.append(self._l[self._index]) self._index+=1 return ret pin=INPUT().stream """ pin(number[default:1],f[default:int],f2[default:False]) if number==0 -> return left all listを変数で受け取るとき、必ずlistをTrueにすること。 """ from sys import setrecursionlimit from collections import deque setrecursionlimit(10000000) def main(): N,Q=pin(2) d=[[]for _ in[0]*N] for _ in[0]*(N-1): a,b=pin(2) d[a-1].append(b-1) d[b-1].append(a-1) cnt=[1]*N B=[0]*N def f(i): B[i]=1 for j in d[i]: if B[j]==0: f(j) cnt[i]+=cnt[j] return f(0) ans=0 for _ in[0]*Q: p,x=pin(2) ans+=cnt[p-1]*x print(ans) return main()