結果

問題 No.1817 Reversed Edges
ユーザー mkawa2mkawa2
提出日時 2022-01-21 22:08:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 499 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 11,068 KB
実行使用メモリ 29,316 KB
最終ジャッジ日時 2023-08-17 06:12:07
合計ジャッジ時間 9,013 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,060 KB
testcase_01 AC 17 ms
8,228 KB
testcase_02 AC 16 ms
8,092 KB
testcase_03 AC 17 ms
8,100 KB
testcase_04 AC 16 ms
8,096 KB
testcase_05 AC 15 ms
8,112 KB
testcase_06 AC 16 ms
8,028 KB
testcase_07 AC 404 ms
24,252 KB
testcase_08 AC 183 ms
16,032 KB
testcase_09 AC 385 ms
23,416 KB
testcase_10 AC 211 ms
17,008 KB
testcase_11 AC 271 ms
19,596 KB
testcase_12 AC 460 ms
26,448 KB
testcase_13 AC 467 ms
26,540 KB
testcase_14 AC 470 ms
26,452 KB
testcase_15 AC 467 ms
26,456 KB
testcase_16 AC 453 ms
26,576 KB
testcase_17 AC 476 ms
26,516 KB
testcase_18 AC 480 ms
26,456 KB
testcase_19 AC 464 ms
26,440 KB
testcase_20 AC 499 ms
27,988 KB
testcase_21 AC 489 ms
26,460 KB
testcase_22 AC 326 ms
24,548 KB
testcase_23 AC 330 ms
24,144 KB
testcase_24 AC 336 ms
29,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 18446744073709551615
# inf = 4294967295
# md = 10**9+7
md = 998244353

n = II()
to = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = LI1()
    to[u].append(v)
    to[v].append(u)

dp = [0]*n
st = [0]
base = 0
par = [-1]*n
while st:
    u = st.pop()
    for v in to[u]:
        if v == par[u]: continue
        par[v] = u
        if u < v:
            dp[v] = dp[u]+1
        else:
            dp[v] = dp[u]-1
            base += 1
        st.append(v)

for c in dp:
    print(c+base)
0