結果
| 問題 |
No.1817 Reversed Edges
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-21 21:59:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 424 ms / 2,000 ms |
| コード長 | 651 bytes |
| コンパイル時間 | 195 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 192,176 KB |
| 最終ジャッジ日時 | 2024-11-26 00:01:27 |
| 合計ジャッジ時間 | 8,290 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 23 |
ソースコード
import sys
sys.setrecursionlimit(3*10**5)
n = int(input())
e = [[] for i in range(n)]
for i in range(n-1):
a,b = [int(x)-1 for x in input().split()]
e[a].append(b)
e[b].append(a)
def dfs(x,p):
count = 0
for nex in e[x]:
if nex == p:
continue
if nex < x:
count += 1
count += dfs(nex,x)
return count
ans = [0]*n
ans[0] = dfs(0,-1)
def dfs2(x,p):
if x != 0:
if p > x:
ans[x] = ans[p]-1
else:
ans[x] = ans[p]+1
for nex in e[x]:
if nex == p:
continue
dfs2 (nex,x)
dfs2(0,-1)
for i in ans:
print(i)