結果

問題 No.1817 Reversed Edges
ユーザー ikomaikoma
提出日時 2022-01-21 22:57:40
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 515 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 99,904 KB
最終ジャッジ日時 2023-08-17 07:22:29
合計ジャッジ時間 6,812 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,420 KB
testcase_01 AC 75 ms
71,452 KB
testcase_02 AC 75 ms
71,352 KB
testcase_03 AC 75 ms
71,320 KB
testcase_04 AC 74 ms
71,384 KB
testcase_05 AC 74 ms
71,320 KB
testcase_06 AC 75 ms
71,280 KB
testcase_07 AC 219 ms
89,652 KB
testcase_08 AC 157 ms
83,212 KB
testcase_09 AC 213 ms
88,568 KB
testcase_10 AC 164 ms
84,076 KB
testcase_11 AC 182 ms
85,628 KB
testcase_12 AC 258 ms
90,848 KB
testcase_13 AC 256 ms
90,636 KB
testcase_14 AC 248 ms
90,752 KB
testcase_15 AC 252 ms
90,748 KB
testcase_16 AC 240 ms
91,040 KB
testcase_17 AC 256 ms
90,864 KB
testcase_18 AC 255 ms
90,896 KB
testcase_19 AC 262 ms
90,852 KB
testcase_20 AC 256 ms
90,824 KB
testcase_21 AC 252 ms
90,968 KB
testcase_22 AC 163 ms
99,904 KB
testcase_23 AC 165 ms
98,468 KB
testcase_24 AC 154 ms
90,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

ans = 0
dif = [0]*N
visit = [0]*N

que = [0]

while que:
    v = que.pop()
    visit[v]=1
    for to in E[v]:
        if visit[to]:continue
        visit[to]=1
        que.append(to)
        if v>to:
            ans += 1
            dif[to]=dif[v]-1
        else:
            dif[to]=dif[v]+1

for d in dif:
    print(d+ans)
0