結果
| 問題 |
No.1103 Directed Length Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-13 07:50:19 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 538 bytes |
| コンパイル時間 | 228 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 158,628 KB |
| 最終ジャッジ日時 | 2024-10-09 18:59:23 |
| 合計ジャッジ時間 | 5,717 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 21 |
ソースコード
from collections import deque
MOD = 10 ** 9 + 7
n = int(input())
root_cand = [True for _ in range(n)]
edges = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
edges[a - 1].append(b - 1)
root_cand[b - 1] = False
root = root_cand.index(True)
ans = 0
queue = deque()
queue.append(root)
queue.append(0)
while queue:
pos = queue.popleft()
d = queue.popleft()
ans += d * (d + 1) // 2
for n_pos in edges[pos]:
queue.append(n_pos)
queue.append(d + 1)
print(ans)