結果

問題 No.1817 Reversed Edges
ユーザー ああいいああいい
提出日時 2022-01-21 22:26:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 632 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 199,172 KB
最終ジャッジ日時 2023-08-17 06:40:44
合計ジャッジ時間 8,929 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,012 KB
testcase_01 AC 68 ms
71,288 KB
testcase_02 AC 75 ms
71,468 KB
testcase_03 AC 69 ms
71,268 KB
testcase_04 AC 67 ms
71,028 KB
testcase_05 AC 67 ms
71,212 KB
testcase_06 AC 66 ms
71,220 KB
testcase_07 AC 370 ms
91,832 KB
testcase_08 AC 255 ms
85,572 KB
testcase_09 AC 379 ms
92,128 KB
testcase_10 AC 283 ms
86,480 KB
testcase_11 AC 329 ms
88,552 KB
testcase_12 AC 426 ms
94,908 KB
testcase_13 AC 419 ms
93,956 KB
testcase_14 AC 428 ms
93,696 KB
testcase_15 AC 412 ms
94,028 KB
testcase_16 AC 422 ms
94,028 KB
testcase_17 AC 425 ms
94,576 KB
testcase_18 AC 407 ms
94,000 KB
testcase_19 AC 398 ms
93,620 KB
testcase_20 AC 409 ms
93,768 KB
testcase_21 AC 423 ms
94,244 KB
testcase_22 AC 195 ms
92,600 KB
testcase_23 AC 203 ms
92,740 KB
testcase_24 AC 432 ms
199,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import sys
sys.setrecursionlimit(10 ** 8)
def dfs(now = 1,parent = 0):
    count = 0
    for v in G[now]:
        if v == parent:continue
        if now > v:count += 1
        count += dfs(v,now)
    return count
ans = [0] * (N + 1)
ans[1] = dfs()
def dfs2(now = 1,parent = 0):
    for v in G[now]:
        if v == parent:continue
        if now > v:
            ans[v] = ans[now] - 1
        else:
            ans[v] = ans[now] + 1
        dfs2(v,now)
dfs2()
for a in ans[1:]:
    print(a)
0