提出 #29831782


ソースコード 拡げる

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

num_leaf = 0
l = [1e9] * (n + 1)
r = [0] * (n + 1)

stack = [(~1, 0), (1, 0)]
while stack:
    curr, prev = stack.pop()
    if curr > 0:
        if graph[curr] == [prev]:
            num_leaf += 1
            l[curr] = num_leaf
            r[curr] = num_leaf
        else:
            stack.append([~curr, None])
            for next_v in graph[curr]:
                if next_v == prev:
                    continue
                stack.append([next_v, curr])

    else:
        curr = ~curr
        for child_v in graph[curr]:
            l[curr] = min(l[curr], l[child_v])
            r[curr] = max(r[curr], r[child_v])

for i in range(1, n + 1):
    print(l[i], r[i])

提出情報

提出日時
問題 E - Ranges on Tree
ユーザ cocoinit23
言語 PyPy3 (7.3.0)
得点 500
コード長 863 Byte
結果 AC
実行時間 671 ms
メモリ 133864 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 33
セット名 テストケース
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, example0.txt, example1.txt, example2.txt
ケース名 結果 実行時間 メモリ
000.txt AC 61 ms 61908 KiB
001.txt AC 480 ms 133864 KiB
002.txt AC 481 ms 131992 KiB
003.txt AC 671 ms 129228 KiB
004.txt AC 650 ms 125096 KiB
005.txt AC 568 ms 102528 KiB
006.txt AC 614 ms 117840 KiB
007.txt AC 630 ms 115768 KiB
008.txt AC 580 ms 131880 KiB
009.txt AC 512 ms 112492 KiB
010.txt AC 262 ms 85516 KiB
011.txt AC 469 ms 97332 KiB
012.txt AC 130 ms 75688 KiB
013.txt AC 187 ms 80516 KiB
014.txt AC 262 ms 85136 KiB
015.txt AC 244 ms 84072 KiB
016.txt AC 180 ms 79324 KiB
017.txt AC 184 ms 80340 KiB
018.txt AC 299 ms 88372 KiB
019.txt AC 400 ms 94080 KiB
020.txt AC 562 ms 103708 KiB
021.txt AC 545 ms 103436 KiB
022.txt AC 565 ms 104048 KiB
023.txt AC 560 ms 103464 KiB
024.txt AC 560 ms 103344 KiB
025.txt AC 564 ms 103916 KiB
026.txt AC 561 ms 103460 KiB
027.txt AC 556 ms 103556 KiB
028.txt AC 567 ms 103152 KiB
029.txt AC 563 ms 103868 KiB
example0.txt AC 49 ms 61796 KiB
example1.txt AC 49 ms 61744 KiB
example2.txt AC 50 ms 62004 KiB