結果
問題 | No.1103 Directed Length Sum |
ユーザー |
|
提出日時 | 2020-07-09 20:58:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,730 ms / 3,000 ms |
コード長 | 490 bytes |
コンパイル時間 | 261 ms |
コンパイル使用メモリ | 82,256 KB |
実行使用メモリ | 214,724 KB |
最終ジャッジ日時 | 2024-10-08 07:02:40 |
合計ジャッジ時間 | 16,845 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
n=int(input())mod=10**9+7es=[[] for _ in range(n)]par=[-1]*nfor _ in range(n-1):a,b=map(int,input().split())es[a-1].append(b-1)if par[b-1]==-1:par[b-1]=a-1for i in range(n):if par[i]==-1:root=ibreak# dfsfrom collections import deque, Counterstack=deque([(root,0)])ans=0while stack:now,depth=stack.pop()for e in es[now]:stack.append((e, depth+1))ans+=(depth+1)*(depth+2)//2ans%=modprint(ans%mod)