結果

問題 No.1817 Reversed Edges
ユーザー tktk_snsntktk_snsn
提出日時 2022-05-13 12:35:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 674 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 32,356 KB
最終ジャッジ日時 2023-09-28 15:28:55
合計ジャッジ時間 11,302 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,880 KB
testcase_01 AC 16 ms
7,976 KB
testcase_02 WA -
testcase_03 AC 16 ms
7,800 KB
testcase_04 AC 16 ms
7,772 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 318 ms
27,136 KB
testcase_23 AC 331 ms
27,108 KB
testcase_24 AC 343 ms
32,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


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

par = [-1] * N
topo = []
que = [0]
while que:
    s = que.pop()
    topo.append(s)
    for t in G[s]:
        if t == par[s]:
            continue
        par[t] = s
        que.append(t)


dp = [0] * N
for s in topo[::-1][:-1]:
    p = par[s]
    dp[p] = dp[s]
    if p > s:
        dp[p] += 1

for s in topo[1:]:
    p = par[s]
    dp[s] = dp[p]
    if p > s:
        dp[s] -= 1
    else:
        dp[s] += 1

print(*dp, sep="\n")
0