Submission #24915327
Source Code Expand
import sys
sys.setrecursionlimit(10**6)
N=int(input())
G=[[]for _ in range(N+1)] #隣接リスト
for _ in range(N-1):
a,b=map(int,input().split())
G[a].append(b)
G[b].append(a)
for i in range(N+1):
G[i].sort()
A=[]
V=[1]*(N+1)
V[1]=0
def dfs(i):
A.append(i)
for j in G[i]:
if V[j]:
V[j]=0
dfs(j)
if A[-1]!=i:
A.append(i)
dfs(1)
print(*A)
Submission Info
| Submission Time | |
|---|---|
| Task | D - Takahashi Tour |
| User | Pandruant |
| Language | Python (3.8.2) |
| Score | 400 |
| Code Size | 376 Byte |
| Status | AC |
| Exec Time | 1158 ms |
| Memory | 212144 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt |
| All | hand_01.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, sample_01.txt, sample_02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| hand_01.txt | AC | 17 ms | 8864 KiB |
| random_01.txt | AC | 542 ms | 37272 KiB |
| random_02.txt | AC | 836 ms | 50560 KiB |
| random_03.txt | AC | 69 ms | 11684 KiB |
| random_04.txt | AC | 833 ms | 50488 KiB |
| random_05.txt | AC | 114 ms | 14640 KiB |
| random_06.txt | AC | 813 ms | 50412 KiB |
| random_07.txt | AC | 1080 ms | 195716 KiB |
| random_08.txt | AC | 1158 ms | 212144 KiB |
| random_09.txt | AC | 821 ms | 50252 KiB |
| random_10.txt | AC | 819 ms | 50048 KiB |
| random_11.txt | AC | 755 ms | 46624 KiB |
| random_12.txt | AC | 719 ms | 46060 KiB |
| random_13.txt | AC | 792 ms | 51816 KiB |
| random_14.txt | AC | 786 ms | 52196 KiB |
| sample_01.txt | AC | 17 ms | 8956 KiB |
| sample_02.txt | AC | 22 ms | 8920 KiB |