結果

問題 No.1607 Kth Maximum Card
ユーザー phsplsphspls
提出日時 2022-10-26 11:02:34
言語 Rust
(1.77.0)
結果
AC  
実行時間 638 ms / 3,500 ms
コード長 1,768 bytes
コンパイル時間 3,401 ms
コンパイル使用メモリ 141,316 KB
実行使用メモリ 27,164 KB
最終ジャッジ日時 2023-09-17 04:28:40
合計ジャッジ時間 13,944 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 424 ms
27,084 KB
testcase_09 AC 409 ms
22,660 KB
testcase_10 AC 599 ms
27,164 KB
testcase_11 AC 56 ms
8,276 KB
testcase_12 AC 404 ms
21,788 KB
testcase_13 AC 38 ms
5,636 KB
testcase_14 AC 49 ms
6,808 KB
testcase_15 AC 272 ms
19,348 KB
testcase_16 AC 40 ms
5,912 KB
testcase_17 AC 12 ms
4,376 KB
testcase_18 AC 170 ms
13,852 KB
testcase_19 AC 91 ms
9,584 KB
testcase_20 AC 126 ms
11,396 KB
testcase_21 AC 151 ms
12,456 KB
testcase_22 AC 537 ms
26,680 KB
testcase_23 AC 574 ms
26,592 KB
testcase_24 AC 122 ms
10,028 KB
testcase_25 AC 58 ms
7,272 KB
testcase_26 AC 83 ms
8,268 KB
testcase_27 AC 143 ms
10,336 KB
testcase_28 AC 114 ms
8,804 KB
testcase_29 AC 310 ms
16,656 KB
testcase_30 AC 638 ms
25,588 KB
testcase_31 AC 277 ms
15,368 KB
testcase_32 AC 97 ms
15,076 KB
testcase_33 AC 98 ms
15,108 KB
testcase_34 AC 104 ms
15,108 KB
testcase_35 AC 105 ms
15,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::{VecDeque, BTreeSet};

const INF: usize = 1usize << 60;

fn main() {
    let mut nmk = String::new();
    std::io::stdin().read_line(&mut nmk).ok();
    let nmk: Vec<usize> = nmk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nmk[0];
    let m = nmk[1];
    let k = nmk[2];
    let mut paths = vec![vec![]; n];
    let mut costset = BTreeSet::new();
    for _ in 0..m {
        let mut temp = String::new();
        std::io::stdin().read_line(&mut temp).ok();
        let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let u = temp[0]-1;
        let v = temp[1]-1;
        let c = temp[2];
        paths[u].push((v, c));
        paths[v].push((u, c));
        costset.insert(c);
    }
    
    costset.insert(0);
    let costs = costset.into_iter().collect::<Vec<_>>();
    let mut lower = 0usize;
    let mut upper = costs.len()-1;
    while upper > lower {
        let middle = (upper + lower) / 2;
        let mut deque = VecDeque::new();
        deque.push_back(0);
        let mut costmap = vec![INF; n];
        costmap[0] = 0;
        let th = costs[middle];
        while let Some(u) = deque.pop_front() {
            for &(v, c) in paths[u].iter() {
                let ncost = costmap[u] + if th >= c { 0 } else { 1 };
                if costmap[v] <= ncost { continue; }
                costmap[v] = ncost;
                if th >= c {
                    deque.push_front(v);
                } else if ncost < k {
                    deque.push_back(v);
                }
            }
        }
        if costmap[n-1] < k {
            upper = middle;
        } else {
            lower = middle + 1;
        }
    }
    println!("{}", costs[upper]);
}
0