結果
問題 | No.1103 Directed Length Sum |
ユーザー |
|
提出日時 | 2022-07-21 23:51:47 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 486 bytes |
コンパイル時間 | 161 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 200,064 KB |
最終ジャッジ日時 | 2024-07-03 08:54:30 |
合計ジャッジ時間 | 18,049 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 WA * 1 |
ソースコード
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)