結果

問題 No.1817 Reversed Edges
ユーザー AEn
提出日時 2022-09-06 22:57:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 630 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 49,176 KB
最終ジャッジ日時 2024-11-21 23:01:46
合計ジャッジ時間 13,259 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**8)

N = int(input())
G = [list() for _ in range(N)]
for i in range(N-1):
    a, b = map(int,input().split())
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)

cnt = 0
def dfs(v, p):
    global cnt
    for nex in G[v]:
        if nex==p:
            continue
        if nex<v:
            cnt += 1
        dfs(nex, v)

res = [0]*N
res[0] = cnt
def dfs_ans(v, p):
    for nex in G[v]:
        if nex==p:
            continue
        if nex>v:
            res[nex] = res[v]+1
        else:
            res[nex] = res[v]-1
        dfs_ans(nex, v)
dfs(0, -1)
dfs_ans(0, -1)
print(*res, sep='\n')
0