結果
問題 | No.1103 Directed Length Sum |
ユーザー | rlangevin |
提出日時 | 2023-01-02 17:31:09 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 489 bytes |
コンパイル時間 | 516 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 144,384 KB |
最終ジャッジ日時 | 2024-05-05 06:31:48 |
合計ジャッジ時間 | 10,979 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
17,568 KB |
testcase_01 | AC | 27 ms
10,496 KB |
testcase_02 | RE | - |
testcase_03 | AC | 2,904 ms
120,704 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
ソースコード
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**6) from functools import lru_cache @lru_cache(maxsize=1024) def f(n): dp, size = 0, 1 for u in G[n]: a, b = f(u) dp += a + b size += b return dp, size N = int(readline()) G = [[] for i in range(N)] for i in range(N - 1): A, B = map(int, readline().split()) A, B = A - 1, B - 1 G[A].append(B) ans = 0 for i in range(N): a, b = f(i) ans += a print(ans)