結果
| 問題 | No.1103 Directed Length Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-03 21:34:11 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1,851 ms / 3,000 ms |
| + 674µs | |
| コード長 | 459 bytes |
| 記録 | |
| コンパイル時間 | 262 ms |
| コンパイル使用メモリ | 95,972 KB |
| 実行使用メモリ | 387,200 KB |
| 最終ジャッジ日時 | 2026-08-29 03:07:55 |
| 合計ジャッジ時間 | 18,675 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
MOD = 10**9 + 7
inpl = lambda: list(map(int,input().split()))
N = int(input())
children = [set() for _ in range(N)]
parent = [None] * N
for _ in range(N-1):
A, B = inpl()
A, B = A-1, B-1
children[A].add(B)
parent[B] = A
forward, back = 0, 1
root = parent.index(None)
ans = 0
pool = [(root,0)]
while pool:
node, d = pool.pop()
ans += d * (d+1) // 2
ans %= MOD
for c in children[node]:
pool.append((c, d+1))
print(ans)