Last active
June 27, 2020 11:55
-
-
Save AnthonyMikh/69db3540e1df3b5a0dd6a9781a3a5063 to your computer and use it in GitHub Desktop.
Generation of problematic test case for "Cheapest Flights Within K Stops" Leetcode problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let width = 9_usize; | |
let total = width * width + 2; | |
let len = width * width * (width - 1) + width * 2; | |
let mut out = Vec::with_capacity(len); | |
for i in 0..width { | |
out.push([0, i + 1, 100]); | |
} | |
for layer in 0..width - 1 { | |
let base = layer * width + 1; | |
for src in base..base + width { | |
for dst in base + width..base + width * 2 { | |
out.push([src, dst, 100]) | |
} | |
} | |
} | |
let last_base = (width - 1) * width + 1; | |
for src in last_base..last_base + width { | |
out.push([src, total - 1, 100]) | |
} | |
// Change to true to make a somewhat more readable output. | |
// Note that this output can't be used "as is" for Leetcode testing system | |
let pretty_print = false; | |
println!("{}", total); // n | |
if !pretty_print { | |
println!("{:?}", out); | |
} | |
if pretty_print { | |
println!("["); | |
for chunk in out.chunks_exact(9) { | |
print!(" "); | |
for edge in chunk { | |
print!("{:2?}, ", edge); | |
} | |
println!() | |
} | |
println!("]"); | |
} | |
println!("0\n{0}\n{0}", total - 1); // src, dst, k | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment