fn search(input: &[Vertex]) -> (usize, usize) {
    let sources = input.iter().map(|v| v.source.as_ref());
    let dests = input.iter().map(|v| v.dest.as_ref());
    let cities = sources.chain(dests).collect::<HashSet<&str>>();

    let forward = input
        .iter()
        .map(|v| ((v.source.as_ref(), v.dest.as_ref()), v.weight));
    let backward = input
        .iter()
        .map(|v| ((v.dest.as_ref(), v.source.as_ref()), v.weight));
    let edges = forward
        .chain(backward)
        .collect::<HashMap<(&str, &str), usize>>();

    let mut min_weight = usize::MAX;
    let mut max_weight = usize::MIN;

    for p in cities.iter().permutations(cities.len()) {
        let mut weight = 0usize;

        for (&&src, &&dest) in p.iter().zip(p.iter().skip(1)) {
            let key = (src, dest);
            weight += edges.get(&key).unwrap_or(&99999usize);
        }

        if weight < min_weight {
            min_weight = weight;
        }

        if weight > max_weight {
            max_weight = weight;
        }
    }

    (min_weight, max_weight)
}
/// Find the min and max path between the given vertices
Find the min and max path between the given vertices
Find the min and max path between the given vertices
fn search(input: &[Vertex]) -> (usize, usize) {
    let sources = input.iter().map(|v| v.source.as_ref());
    let dests = input.iter().map(|v| v.dest.as_ref());
    let cities = sources.chain(dests).collect::<HashSet<&str>>();
    let forward = input
        .iter()
        .map(|v| ((v.source.as_ref(), v.dest.as_ref()), v.weight));
    let backward = input
        .iter()
        .map(|v| ((v.dest.as_ref(), v.source.as_ref()), v.weight));
    let edges = forward
        .chain(backward)
        .collect::<HashMap<(&str, &str), usize>>();
    let mut min_weight = usize::MAX;
    let mut max_weight = usize::MIN;
    for p in cities.iter().permutations(cities.len()) {
        let mut weight = 0usize;
        for (&&src, &&dest) in p.iter().zip(p.iter().skip(1)) {
            let key = (src, dest);
            weight += edges.get(&key).unwrap_or(&99999usize);
        }
        if weight < min_weight {
            min_weight = weight;
        }
        if weight > max_weight {
            max_weight = weight;
        }
    }
    (min_weight, max_weight)
}
fn search ( input : & [ Vertex ] ) -> ( usize , usize ) { let sources = input . iter ( ) . map ( | v | v . source . as_ref ( ) ) ; let dests = input . iter ( ) . map ( | v | v . dest . as_ref ( ) ) ; let cities = sources . chain ( dests ) . collect :: < HashSet < & str > > ( ) ; let forward = input . iter ( ) . map ( | v | ( ( v . source . as_ref ( ) , v . dest . as_ref ( ) ) , v . weight ) ) ; let backward = input . iter ( ) . map ( | v | ( ( v . dest . as_ref ( ) , v . source . as_ref ( ) ) , v . weight ) ) ; let edges = forward . chain ( backward ) . collect :: < HashMap < ( & str , & str ) , usize > > ( ) ; let mut min_weight = usize :: MAX ; let mut max_weight = usize :: MIN ; for p in cities . iter ( ) . permutations ( cities . len ( ) ) { let mut weight = 0usize ; for ( & & src , & & dest ) in p . iter ( ) . zip ( p . iter ( ) . skip ( 1 ) ) { let key = ( src , dest ) ; weight += edges . get ( & key ) . unwrap_or ( & 99999usize ) ; } if weight < min_weight { min_weight = weight ; } if weight > max_weight { max_weight = weight ; } } ( min_weight , max_weight ) }
Find the min and max path between the given vertices
Find the min and max path between the given vertices
input
&[Vertex]
input
&[Vertex]