CSES - Datatähti 2023 alku - Results
Submission details
Task:Sadonkorjuu
Sender:drvilepis
Submission time:2022-11-01 15:57:06 +0200
Language:Rust
Status:COMPILE ERROR

Compiler report

error: expected `;`, found keyword `let`
  --> input/code.rs:14:9
   |
14 |     bruh
   |         ^ help: add `;` here
15 | 
16 |     let mut input = String::new();
   |     --- unexpected token

error[E0425]: cannot find value `bruh` in this scope
  --> input/code.rs:14:5
   |
14 |     bruh
   |     ^^^^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.

Code

use std::collections::HashMap;

fn sort(i: usize, j: usize) -> (usize, usize) {
    if i < j {
        (i, j)
    } else {
        (j, i)
    }
}

fn main() {
    let stdin = std::io::stdin();

    bruh

    let mut input = String::new();

    stdin.read_line(&mut input).unwrap();
    let n_cities = input.trim().parse::<usize>().unwrap();
    input.clear();

    stdin.read_line(&mut input).unwrap();

    // true on satama, false on pelto
    let types = input.split_whitespace().map(|c| c.chars().next().unwrap() == '0').collect::<Vec<_>>();
    input.clear();

    let mut lenmap = HashMap::new();
    let mut bridgemap: HashMap<usize, Vec<usize>> = HashMap::new();

    loop {
        let res = stdin.read_line(&mut input).unwrap();

        if res == 0 {
            break;
        };

        let mut nums = input.split_whitespace().map(|c| c.parse::<usize>().unwrap());
        let (i, j) = (nums.next().unwrap() - 1, nums.next().unwrap() - 1);

        let (i, j) = sort(i, j);

        lenmap.insert((i, j), nums.next().unwrap());

        if let Some(vec) = bridgemap.get_mut(&i) {
            vec.push(j)
        } else {
            bridgemap.insert(i, vec![j]);
        }

        if let Some(vec) = bridgemap.get_mut(&j) {
            vec.push(i)
        } else {
            bridgemap.insert(j, vec![i]);
        }

        input.clear();
    }

    let mut min_dists = vec![0; n_cities];

    types.iter().enumerate().for_each(|(i, &t)| {
        if !t {
            return;
        }

        let mut nums: Vec<(usize, Option<usize>, usize)> = vec![];

        nums.push((i, None, 0));

        loop {
            nums = nums.iter().map(|&(cur_node, last_node_opt, length)| {
                let other_nodes = bridgemap.get(&cur_node).unwrap().clone();

                let mut out = vec![];

                for other_node in other_nodes {
                    if let Some(last_node) = last_node_opt {
                        if other_node == last_node {
                            continue;
                        }
                    };

                    let new_length = length + *lenmap.get(&sort(other_node, cur_node)).unwrap();

                    if !types[other_node] {
                        if min_dists[other_node] != 0 {
                            if new_length < min_dists[other_node] {
                                min_dists[other_node] = new_length;
                            } else {
                                continue;
                            }
                        } else {
                            min_dists[other_node] = new_length;
                        }
                        out.push((other_node, Some(cur_node), new_length));
                    }
                }

                out
            }).flatten().collect();

            if nums.is_empty() {
                break;
            }
        }
    });

    let sum = min_dists.into_iter().sum::<usize>();

    println!("{}", sum);
}