結果

問題 No.2387 Yokan Factory
ユーザー 👑 MizarMizar
提出日時 2023-07-01 17:28:50
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,374 bytes
コンパイル時間 4,474 ms
コンパイル使用メモリ 156,212 KB
実行使用メモリ 8,804 KB
最終ジャッジ日時 2023-09-22 11:41:43
合計ジャッジ時間 6,896 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 124 ms
8,544 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 67 ms
4,592 KB
testcase_26 AC 93 ms
6,276 KB
testcase_27 AC 58 ms
7,408 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 1 ms
4,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
4,380 KB
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// -*- coding:utf-8-unix -*-
use std::{cmp::Reverse, collections::BinaryHeap, io::prelude::*};

fn main() {
    let stdin = std::io::stdin();
    let mut lines = stdin.lock().lines();

    let (n, m, x) = {
        let l = lines.next().unwrap().unwrap();
        let mut t = l.split_ascii_whitespace();
        let n = t.next().unwrap().parse::<usize>().unwrap();
        let m = t.next().unwrap().parse::<usize>().unwrap();
        let x = t.next().unwrap().parse::<u64>().unwrap();
        (n, m, x)
    };
    let n1 = n - 1;
    let mut g = (0..n)
        .map(|_| Vec::<(u32, u32, u32)>::new())
        .collect::<Vec<_>>();
    let mut yokan = (0u32, 1000000000u32);
    let mut queue = BinaryHeap::with_capacity(n + m);

    for _ in 0..m {
        let l = lines.next().unwrap().unwrap();
        let mut t = l.split_ascii_whitespace();
        let u = t.next().unwrap().parse::<u32>().unwrap() - 1;
        let v = t.next().unwrap().parse::<u32>().unwrap() - 1;
        let a = t.next().unwrap().parse::<u32>().unwrap();
        let b = t.next().unwrap().parse::<u32>().unwrap();

        g[u as usize].push((v, a, b));
        g[v as usize].push((u, a, b));
    }
    for p in g.iter_mut() {
        p.sort_by_key(|e| e.2);
    }

    while yokan.0 < yokan.1 {
        let pivot = (yokan.1 - yokan.0 + 1) / 2 + yokan.0;
        let mut dists = vec![1u64 << 60; n];
        dists[0] = 0;
        queue.clear();
        queue.push(Reverse((0u64, 0usize)));
        while let Some(Reverse((pd, i))) = queue.pop() {
            if dists[i] < pd {
                continue;
            }
            for &(j, a, b) in g[i].iter() {
                let ju = j as usize;
                let nd = pd + (a as u64);
                if b < pivot {
                    break;
                }
                if nd > x || dists[ju] <= nd {
                    continue;
                }
                dists[ju] = nd;
                if ju == n1 {
                    queue.clear();
                    break;
                }
                queue.push(Reverse((nd, ju)));
            }
        }
        if dists[n1] <= x {
            yokan.0 = pivot;
        } else {
            yokan.1 = pivot - 1;
        }
    }

    println!(
        "{}",
        if yokan.0 == 0 {
            "-1".to_string()
        } else {
            yokan.0.to_string()
        }
    );
}
0