Submission #35812113


Source Code Expand

from collections import deque
import sys

sys.setrecursionlimit(2 * 10 ** 6)

route = []
def C(N, X, Y, UV):
    def dfs(n):
        route.append(n)
        if n == Y:
            print(*route)
            exit()
            
        for nxt in edge[n]:
            if len(route) >= 2 and nxt == route[-2]:
                continue
            else:
                dfs(nxt)
        route.pop()
                
    edge = [[] for _ in range(N+1)]
    for u, v in UV:
        edge[u].append(v)
        edge[v].append(u)
    
    dfs(X)
 
N, X, Y = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(N-1)]
print(C(N, X, Y, UV))

Submission Info

Submission Time
Task C - Simple path
User arakaki_tokyo
Language Python (3.8.2)
Score 300
Code Size 683 Byte
Status AC
Exec Time 1255 ms
Memory 299428 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 27
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 24 ms 9300 KiB
example_01.txt AC 24 ms 9428 KiB
hand_00.txt AC 19 ms 9160 KiB
hand_01.txt AC 1254 ms 299428 KiB
hand_02.txt AC 663 ms 67720 KiB
hand_03.txt AC 1253 ms 297752 KiB
hand_04.txt AC 1255 ms 299252 KiB
random_00.txt AC 828 ms 66784 KiB
random_01.txt AC 746 ms 66516 KiB
random_02.txt AC 744 ms 66656 KiB
random_03.txt AC 800 ms 66760 KiB
random_04.txt AC 801 ms 66636 KiB
random_05.txt AC 702 ms 66624 KiB
random_06.txt AC 682 ms 66652 KiB
random_07.txt AC 760 ms 66536 KiB
random_08.txt AC 725 ms 66524 KiB
random_09.txt AC 671 ms 68712 KiB
random_10.txt AC 699 ms 68948 KiB
random_11.txt AC 690 ms 68800 KiB
random_12.txt AC 1107 ms 250652 KiB
random_13.txt AC 1092 ms 223652 KiB
random_14.txt AC 1093 ms 238840 KiB
random_15.txt AC 1115 ms 258252 KiB
random_16.txt AC 1040 ms 222320 KiB
random_17.txt AC 750 ms 87960 KiB
random_18.txt AC 1024 ms 166832 KiB
random_19.txt AC 759 ms 92744 KiB