結果

問題 No.1817 Reversed Edges
ユーザー moharan627moharan627
提出日時 2022-01-21 22:22:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,084 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 94,128 KB
最終ジャッジ日時 2024-05-04 13:29:16
合計ジャッジ時間 5,010 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
53,376 KB
testcase_01 AC 42 ms
53,632 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 43 ms
53,760 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 137 ms
94,128 KB
testcase_23 AC 132 ms
93,696 KB
testcase_24 AC 139 ms
89,216 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[t] = Ans[s]+1
                else:
                    Ans[t] = Ans[s]-1
                Q.append(t)
    for n in range(N):
        print(Ans[n])
    return
solve()
0