結果
問題 | No.1103 Directed Length Sum |
ユーザー |
![]() |
提出日時 | 2020-07-03 22:34:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,485 ms / 3,000 ms |
コード長 | 470 bytes |
コンパイル時間 | 246 ms |
コンパイル使用メモリ | 82,312 KB |
実行使用メモリ | 192,088 KB |
最終ジャッジ日時 | 2024-09-17 04:16:03 |
合計ジャッジ時間 | 14,388 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
from collections import dequeN = int(input())E = [[] for _ in range(N)]par = [-1]*Nfor _ in range(N-1):a,b = map(int, input().split())E[a-1].append(b-1)par[b-1] = a-1for i in range(N):if par[i] == -1:root = ibreakans = 0mod = 10**9+7q = deque()q.append(root)while q:temp = q.pop()p = temp%Nrnk = temp//Nans += rnk*(rnk+1)//2ans %= modfor v in E[p]:q.append((rnk+1)*N+v)print(ans)