結果

問題 No.1817 Reversed Edges
ユーザー tassei903tassei903
提出日時 2022-01-21 22:01:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 1,093 ms
コンパイル使用メモリ 85,688 KB
実行使用メモリ 109,352 KB
最終ジャッジ日時 2023-08-17 06:01:39
合計ジャッジ時間 7,115 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,888 KB
testcase_01 AC 74 ms
70,784 KB
testcase_02 AC 75 ms
71,008 KB
testcase_03 AC 78 ms
70,636 KB
testcase_04 AC 74 ms
70,840 KB
testcase_05 AC 75 ms
70,656 KB
testcase_06 AC 76 ms
70,764 KB
testcase_07 AC 263 ms
98,840 KB
testcase_08 AC 173 ms
86,532 KB
testcase_09 AC 246 ms
97,840 KB
testcase_10 AC 190 ms
88,500 KB
testcase_11 AC 214 ms
91,180 KB
testcase_12 AC 286 ms
101,820 KB
testcase_13 AC 286 ms
101,600 KB
testcase_14 AC 289 ms
101,940 KB
testcase_15 AC 290 ms
101,612 KB
testcase_16 AC 284 ms
101,452 KB
testcase_17 AC 285 ms
101,908 KB
testcase_18 AC 282 ms
101,940 KB
testcase_19 AC 292 ms
101,580 KB
testcase_20 AC 278 ms
101,916 KB
testcase_21 AC 283 ms
101,756 KB
testcase_22 AC 190 ms
109,352 KB
testcase_23 AC 191 ms
105,196 KB
testcase_24 AC 180 ms
98,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

n = ni()
g = [[] for i in range(n)]
for i in range(n-1):
    a,b=na()
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)

dq = [0]
dp = [0]*n
seen = [0]*n
et = []
oya = [-1]*n
while dq:
    v = dq.pop()
    seen[v] = 1
    et.append(v)
    for w in g[v]:
        if seen[w]^1:
            dq.append(w)
            oya[w] = v
            if v>w:
                dp[0] += 1

for i in et[1:]:
    if i>oya[i]:
        dp[i] = dp[oya[i]]+1
    else:
        dp[i] = dp[oya[i]]-1
print(*dp,sep="\n")
0