結果

問題 No.1817 Reversed Edges
ユーザー ShirotsumeShirotsume
提出日時 2022-01-21 23:07:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 935 bytes
コンパイル時間 1,042 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 102,164 KB
最終ジャッジ日時 2023-08-17 07:39:37
合計ジャッジ時間 9,151 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,540 KB
testcase_01 AC 90 ms
71,740 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 92 ms
71,616 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 245 ms
99,244 KB
testcase_23 AC 259 ms
102,164 KB
testcase_24 AC 241 ms
97,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
graph = [[] for _ in range(n)]
edge = []
for _ in range(n - 1):
    a, b = map(int,input().split())
    a -= 1; b -= 1
    edge.append((a, b))
    graph[a].append(b)
    graph[b].append(a)

value = [0] * n
visit = [-1] * n
visit[0] = 0
from collections import deque
q = deque()
q.append(0)
while q:
    now = q.popleft()
    for to in graph[now]:
        if visit[to] < 0:
            visit[to] = visit[now] + 1
            q.append(to)
depth = visit
for a, b in edge:
    if a > b: a, b = b, a
    #a < bを仮定
    if depth[a] > depth[b]:
        value[b] -= 1
        value[0] += 1
    else:
        value[b] += 1
        
        
visit = [False] * n
visit[0] = True
q = deque()
q.append(0)
while q:
    now = q.popleft()
    for to in graph[now]:
        if depth[to] > depth[now]:
            visit[to] = visit[now] + 1
            value[to] += value[now]
            q.append(to)

for v in value:
    print(v)
0