結果
問題 | No.1103 Directed Length Sum |
ユーザー | anagohirame |
提出日時 | 2020-07-04 14:37:02 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 538 bytes |
コンパイル時間 | 545 ms |
コンパイル使用メモリ | 11,928 KB |
実行使用メモリ | 189,560 KB |
最終ジャッジ日時 | 2023-10-19 05:07:17 |
合計ジャッジ時間 | 14,661 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
10,140 KB |
testcase_01 | AC | 29 ms
10,140 KB |
testcase_02 | TLE | - |
testcase_03 | AC | 2,752 ms
143,360 KB |
testcase_04 | AC | 2,295 ms
85,572 KB |
testcase_05 | TLE | - |
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 sys.setrecursionlimit(1000010) def input(): return sys.stdin.buffer.readline()[:-1] MOD = 10**9+7 n = int(input()) aff = [0 for _ in range(n)] adj = [[] for _ in range(n)] for _ in range(n-1): u, v = map(int, input().split()) adj[u-1].append(v-1) aff[v-1] += 1 for i, x in enumerate(aff): if x == 0: root = i break ans = 0 dep = [0 for _ in range(n)] ans = 0 stack = [root] while stack: i = stack.pop() ans += dep[i] * (dep[i]+1) // 2 ans %= MOD for j in adj[i]: dep[j] = dep[i]+1 stack.append(j) print(ans)