結果
| 問題 | No.1103 Directed Length Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-03 22:11:31 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 1,205 ms / 3,000 ms |
| コード長 | 414 bytes |
| 記録 | |
| コンパイル時間 | 149 ms |
| コンパイル使用メモリ | 85,120 KB |
| 実行使用メモリ | 307,968 KB |
| 最終ジャッジ日時 | 2026-04-06 01:48:08 |
| 合計ジャッジ時間 | 11,399 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
import sys
input=sys.stdin.readline
n=int(input())
edge=[[]for _ in range(n)]
to=[0]*n
p=[0]*n
for _ in range(n-1):
a,b=map(int,input().split())
a-=1
b-=1
edge[a].append(b)
to[b]=1
stack=[to.index(0)]
visited=set(stack)
mod=10**9+7
ans=0
for i in stack:
for j in edge[i]:
if j in visited:continue
visited.add(j)
stack.append(j)
p[j]+=p[i]+1
ans+=p[i]*(p[i]+1)//2
ans%=mod
print(ans)