Submission #66772974
Source Code Expand
Copy
n, m = gets.split.map(&:to_i)goto = Array.new(n + 1) { [] }m.times doa, b, w = gets.split.map(&:to_i)goto[a] << [b, w]enddist = Array.new(n + 1)dist[1] = 0queue = [[1, 0]]basis = []until queue.empty?u, cost = queue.shiftgoto[u].each do |v, w|new_cost = cost ^ wif dist[v].nil?dist[v] = new_costqueue << [v, new_cost]else
n, m = gets.split.map(&:to_i)
goto = Array.new(n + 1) { [] }
m.times do
a, b, w = gets.split.map(&:to_i)
goto[a] << [b, w]
end
dist = Array.new(n + 1)
dist[1] = 0
queue = [[1, 0]]
basis = []
until queue.empty?
u, cost = queue.shift
goto[u].each do |v, w|
new_cost = cost ^ w
if dist[v].nil?
dist[v] = new_cost
queue << [v, new_cost]
else
cycle = dist[v] ^ new_cost
basis << cycle if cycle != 0
end
end
end
def reduce(x, basis)
basis.sort_by { |b| -b.bit_length }.each do |b|
x = [x, x ^ b].min
end
x
end
if dist[n].nil?
puts -1
else
puts reduce(dist[n], basis)
end
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | Rinn01 |
| Language | Ruby (ruby 3.2.2) |
| Score | 0 |
| Code Size | 671 Byte |
| Status | WA |
| Exec Time | 45 ms |
| Memory | 17584 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 400 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.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, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| hand_01.txt | AC | 43 ms | 17184 KiB |
| hand_02.txt | AC | 43 ms | 17320 KiB |
| hand_03.txt | AC | 44 ms | 17244 KiB |
| hand_04.txt | AC | 43 ms | 17260 KiB |
| hand_05.txt | AC | 43 ms | 17224 KiB |
| hand_06.txt | WA | 44 ms | 17204 KiB |
| hand_07.txt | WA | 43 ms | 16992 KiB |
| hand_08.txt | WA | 44 ms | 17172 KiB |
| random_01.txt | AC | 44 ms | 17084 KiB |
| random_02.txt | AC | 44 ms | 17344 KiB |
| random_03.txt | AC | 44 ms | 17192 KiB |
| random_04.txt | AC | 45 ms | 17388 KiB |
| random_05.txt | AC | 44 ms | 17128 KiB |
| random_06.txt | AC | 44 ms | 17300 KiB |
| random_07.txt | AC | 44 ms | 17128 KiB |
| random_08.txt | AC | 45 ms | 17400 KiB |
| random_09.txt | AC | 44 ms | 17288 KiB |
| random_10.txt | AC | 45 ms | 17152 KiB |
| random_11.txt | AC | 44 ms | 17120 KiB |
| random_12.txt | AC | 44 ms | 17308 KiB |
| random_13.txt | AC | 44 ms | 17432 KiB |
| random_14.txt | WA | 45 ms | 17536 KiB |
| random_15.txt | WA | 44 ms | 17440 KiB |
| random_16.txt | AC | 44 ms | 17284 KiB |
| random_17.txt | AC | 45 ms | 17268 KiB |
| random_18.txt | AC | 44 ms | 17036 KiB |
| random_19.txt | AC | 45 ms | 17552 KiB |
| random_20.txt | AC | 45 ms | 17476 KiB |
| random_21.txt | AC | 45 ms | 17584 KiB |
| random_22.txt | AC | 45 ms | 17536 KiB |
| sample_01.txt | AC | 43 ms | 17220 KiB |
| sample_02.txt | AC | 44 ms | 17076 KiB |
| sample_03.txt | AC | 44 ms | 17312 KiB |