Submission #34334743
Source Code Expand
n = gets.chomp.to_i
PATHS = Array.new(n + 1) { [] }
(n-1).times do
from, to = gets.chomp.split.map(&:to_i)
PATHS[from] << to
PATHS[to] << from
end
PATHS.each do |next_towns|
next_towns.sort!
end
def dfs(current, visited, route)
visited[current] = true
route << current
PATHS[current].each do |next_town|
next if visited[next_town]
dfs(next_town, visited, route)
route << current
end
end
route = []
dfs(1, Array.new(n + 1), route)
puts route.join(" ")
Submission Info
| Submission Time | |
|---|---|
| Task | D - Takahashi Tour |
| User | thatblue |
| Language | Ruby (2.7.1) |
| Score | 400 |
| Code Size | 513 Byte |
| Status | AC |
| Exec Time | 620 ms |
| Memory | 263960 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 | 56 ms | 14020 KiB |
| random_01.txt | AC | 318 ms | 31468 KiB |
| random_02.txt | AC | 443 ms | 39992 KiB |
| random_03.txt | AC | 81 ms | 15988 KiB |
| random_04.txt | AC | 450 ms | 40032 KiB |
| random_05.txt | AC | 105 ms | 17884 KiB |
| random_06.txt | AC | 439 ms | 40176 KiB |
| random_07.txt | AC | 604 ms | 241252 KiB |
| random_08.txt | AC | 620 ms | 263960 KiB |
| random_09.txt | AC | 453 ms | 37472 KiB |
| random_10.txt | AC | 425 ms | 35924 KiB |
| random_11.txt | AC | 413 ms | 38540 KiB |
| random_12.txt | AC | 406 ms | 39120 KiB |
| random_13.txt | AC | 418 ms | 38668 KiB |
| random_14.txt | AC | 415 ms | 38596 KiB |
| sample_01.txt | AC | 57 ms | 14020 KiB |
| sample_02.txt | AC | 57 ms | 14168 KiB |