結果
問題 | No.1103 Directed Length Sum |
ユーザー |
|
提出日時 | 2022-07-21 23:52:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,503 ms / 3,000 ms |
コード長 | 496 bytes |
コンパイル時間 | 304 ms |
コンパイル使用メモリ | 82,252 KB |
実行使用メモリ | 200,180 KB |
最終ジャッジ日時 | 2024-07-03 08:56:45 |
合計ジャッジ時間 | 15,280 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
import collections N = int(input()) lsg = [[] for i in range(N)] per = [0]*(N) for i in range(N-1): a,b = map(int,input().split()) a -= 1 b -= 1 lsg[a].append(b) per[b] += 1 r = -1 for i in range(N): if per[i] == 0: r = i break d = collections.deque([r]) depth = [0]*(N) while d: x = d.popleft() for j in lsg[x]: depth[j] = depth[x]+1 d.append(j) ans = 0 for i in range(N): ans += (depth[i])*(depth[i]+1)//2 print(ans%(10**9+7))