結果
| 問題 |
No.1103 Directed Length Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-13 07:50:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 538 bytes |
| コンパイル時間 | 604 ms |
| コンパイル使用メモリ | 81,888 KB |
| 実行使用メモリ | 236,520 KB |
| 最終ジャッジ日時 | 2024-10-09 19:00:03 |
| 合計ジャッジ時間 | 15,598 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 WA * 1 |
ソースコード
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)