結果
| 問題 |
No.1103 Directed Length Sum
|
| コンテスト | |
| ユーザー |
Ldio03
|
| 提出日時 | 2020-07-04 00:40:40 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 596 bytes |
| コンパイル時間 | 133 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 302,568 KB |
| 最終ジャッジ日時 | 2024-09-17 05:21:30 |
| 合計ジャッジ時間 | 5,744 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 21 |
ソースコード
from collections import deque
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
depth=[-1]*N
forward, back = 0, 1
root = parent.index(None)
ans = 0
pool = deque([root])
depth[root]=0
while pool:
node = pool.popleft()
ans += depth[node] * (depth[node]+1) // 2
ans %= MOD
for c in children[node]:
if depth[c]!=-1:continue
depth[c]=depth[node]+1
pool.append(c)
print(ans)
Ldio03