結果

問題 No.1817 Reversed Edges
ユーザー moharan627moharan627
提出日時 2022-01-21 22:31:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 366 ms / 2,000 ms
コード長 1,376 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 94,460 KB
最終ジャッジ日時 2023-08-17 06:47:29
合計ジャッジ時間 8,359 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,508 KB
testcase_01 AC 95 ms
71,648 KB
testcase_02 AC 95 ms
71,700 KB
testcase_03 AC 93 ms
71,732 KB
testcase_04 AC 95 ms
71,632 KB
testcase_05 AC 95 ms
71,568 KB
testcase_06 AC 94 ms
71,616 KB
testcase_07 AC 330 ms
90,376 KB
testcase_08 AC 201 ms
84,784 KB
testcase_09 AC 292 ms
89,540 KB
testcase_10 AC 225 ms
85,132 KB
testcase_11 AC 264 ms
86,988 KB
testcase_12 AC 355 ms
92,268 KB
testcase_13 AC 361 ms
92,456 KB
testcase_14 AC 360 ms
92,512 KB
testcase_15 AC 357 ms
92,288 KB
testcase_16 AC 325 ms
92,500 KB
testcase_17 AC 333 ms
92,228 KB
testcase_18 AC 361 ms
92,392 KB
testcase_19 AC 366 ms
92,556 KB
testcase_20 AC 356 ms
92,368 KB
testcase_21 AC 332 ms
92,444 KB
testcase_22 AC 202 ms
94,028 KB
testcase_23 AC 201 ms
94,460 KB
testcase_24 AC 187 ms
91,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(10 ** 6)
INF = float('inf')
#10**20,2**63に変えるのもあり
MOD = 10**9 + 7
MOD2 = 998244353
from collections import defaultdict
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())
    N = II()
    Graph = [[] for _ in range(N)]
    for n in range(N-1):
        A,B = MI()
        A-=1
        B-=1
        Graph[A].append(B)
        Graph[B].append(A)
    from collections import deque
    Q = deque()
    Seen = [False for i in range(N)]
    Ans = [0] * N
    Q.append(0)
    while Q:
        #print(s,Ans)
        s = Q.pop()
        Seen[s] = True
        for t in Graph[s]:
            if Seen[t] == False:
                if s > t :
                    Ans[0]+=1
                Q.append(t)
    Q = deque()
    Seen = [False for i in range(N)]
    Q.append(0)
    while Q:
        #print(s,Ans)
        s = Q.pop()
        Seen[s] = True
        for t in Graph[s]:
            if Seen[t] == False:
                if s < t :
                    Ans[t] = Ans[s]+1
                else:
                    Ans[t] = Ans[s]-1
                Q.append(t)
    for n in range(N):
        print(Ans[n])
    return
solve()
0