結果
問題 | No.1103 Directed Length Sum |
ユーザー |
![]() |
提出日時 | 2020-07-03 22:37:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,192 ms / 3,000 ms |
コード長 | 465 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,080 KB |
実行使用メモリ | 191,364 KB |
最終ジャッジ日時 | 2024-09-17 04:18:52 |
合計ジャッジ時間 | 12,068 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
import sysinput = sys.stdin.buffer.readlinefrom 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-1root = par.index(-1)ans = 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)