結果
| 問題 |
No.1103 Directed Length Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-25 19:26:34 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 466 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 221,724 KB |
| 最終ジャッジ日時 | 2024-06-27 13:32:24 |
| 合計ジャッジ時間 | 15,027 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 TLE * 3 -- * 18 |
ソースコード
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
edge = [[] for _ in range(N)]
roots = [True]*N
for _ in range(N-1):
a,b = map(int, input().split())
roots[b-1] = False
edge[a-1].append(b-1)
ans = 0
mod = 10**9+7
d = deque()
root = roots.index(True)
d.append([root,0])
while len(d)>0:
v,depth = d.popleft()
ans += depth*(depth+1)//2
ans %= mod
for w in edge[v]:
d.append([w,depth+1])
print(ans)