結果
| 問題 |
No.2427 Tree Distance Two
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2023-08-18 23:01:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 447 bytes |
| コンパイル時間 | 355 ms |
| コンパイル使用メモリ | 82,392 KB |
| 実行使用メモリ | 323,328 KB |
| 最終ジャッジ日時 | 2024-11-28 09:33:58 |
| 合計ジャッジ時間 | 30,967 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 TLE * 6 |
ソースコード
from collections import defaultdict
N = int(input())
adj = defaultdict(list)
for _ in range(N-1):
u, v = map(lambda x: int(x)-1, input().split())
adj[u].append(v)
adj[v].append(u)
def dfs(v, prev, depth):
if depth == 2: return 1
res = 0
for to in adj[v]:
if to == prev: continue
res += dfs(to, v, depth+1)
return res
ans = []
for i in range(N):
ans.append(dfs(i, -1, 0))
print(*ans, sep='\n')
norioc