Submission #34067156


Source Code Expand

Copy
use std::{cmp::Reverse, collections::BinaryHeap};
use proconio::{input, marker::Usize1};
fn main() {
input! {
n: usize,
m: usize,
s: usize,
uvab: [(Usize1, Usize1, usize, usize); m],
cd: [(usize, usize); n]
};
let mut edges = vec![vec![]; n];
for (u, v, a, b) in uvab.iter().copied() {
edges[u].push((v, a, b));
edges[v].push((u, a, b));
}
let max_cost = 50 * 50 + 50;
let s = s.min(max_cost);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
use std::{cmp::Reverse, collections::BinaryHeap};

use proconio::{input, marker::Usize1};

fn main() {
    input! {
        n: usize,
        m: usize,
        s: usize,
        uvab: [(Usize1, Usize1, usize, usize); m],
        cd: [(usize, usize); n]
    };

    let mut edges = vec![vec![]; n];
    for (u, v, a, b) in uvab.iter().copied() {
        edges[u].push((v, a, b));
        edges[v].push((u, a, b));
    }

    let max_cost = 50 * 50 + 50;
    let s = s.min(max_cost);
    let inf = 1_usize << 60;
    let mut min_time = vec![vec![inf; 3000 + 1]; n];
    min_time[0][s] = 0;
    let mut pq = BinaryHeap::new();
    pq.push(Reverse((0, 0, s)));
    while let Some(Reverse((time, vert, cost))) = pq.pop() {
        if min_time[vert][cost] != time {
            continue;
        }

        let (c, d) = cd[vert];
        if cost < max_cost {
            let next_vert = vert;
            let next_cost = (cost + c).min(max_cost);
            let next_time = time + d;
            if next_time < min_time[next_vert][next_cost] {
                min_time[next_vert][next_cost] = next_time;
                pq.push(Reverse((next_time, next_vert, next_cost)));
            }
        }

        for (next_vert, a, b) in edges[vert].iter().copied() {
            if cost < a {
                continue;
            }

            let next_cost = cost - a;
            let next_time = time + b;
            if next_time < min_time[next_vert][next_cost] {
                min_time[next_vert][next_cost] = next_time;
                pq.push(Reverse((next_time, next_vert, next_cost)));
            }
        }
    }

    for time in min_time.into_iter().skip(1) {
        let ans = time.into_iter().min().unwrap();
        println!("{}", ans);
    }
}

Submission Info

Submission Time
Task E - Two Currencies
User bouzuya
Language Rust (1.42.0)
Score 500
Code Size 1754 Byte
Status AC
Exec Time 43 ms
Memory 5148 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 5
AC × 27
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
All line_1.txt, line_2.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, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
Case Name Status Exec Time Memory
line_1.txt AC 16 ms 3000 KB
line_2.txt AC 14 ms 2996 KB
random_01.txt AC 40 ms 4132 KB
random_02.txt AC 39 ms 5148 KB
random_03.txt AC 39 ms 4568 KB
random_04.txt AC 38 ms 4588 KB
random_05.txt AC 38 ms 4284 KB
random_06.txt AC 41 ms 4304 KB
random_07.txt AC 39 ms 4124 KB
random_08.txt AC 39 ms 4656 KB
random_09.txt AC 39 ms 4100 KB
random_10.txt AC 39 ms 4928 KB
random_11.txt AC 36 ms 4392 KB
random_12.txt AC 39 ms 4460 KB
random_13.txt AC 43 ms 4332 KB
random_14.txt AC 34 ms 4152 KB
random_15.txt AC 36 ms 3656 KB
random_16.txt AC 42 ms 4740 KB
random_17.txt AC 36 ms 4824 KB
random_18.txt AC 43 ms 3964 KB
random_19.txt AC 38 ms 3940 KB
random_20.txt AC 37 ms 4004 KB
sample_01.txt AC 3 ms 2072 KB
sample_02.txt AC 3 ms 2140 KB
sample_03.txt AC 6 ms 2224 KB
sample_04.txt AC 4 ms 2164 KB
sample_05.txt AC 2 ms 2220 KB


2025-04-11 (Fri)
09:57:37 +00:00