結果
問題 | No.1607 Kth Maximum Card |
ユーザー | phspls |
提出日時 | 2022-11-23 19:41:07 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,090 bytes |
コンパイル時間 | 13,563 ms |
コンパイル使用メモリ | 378,528 KB |
実行使用メモリ | 56,060 KB |
最終ジャッジ日時 | 2024-09-25 00:13:52 |
合計ジャッジ時間 | 19,805 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
56,060 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,948 KB |
testcase_08 | TLE | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
コンパイルメッセージ
warning: field `n` is never read --> src/main.rs:7:5 | 6 | struct Dijkstra { | -------- field in this struct 7 | n: usize, | ^ | = note: `Dijkstra` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis = note: `#[warn(dead_code)]` on by default warning: methods `get_cost` and `reconstruct` are never used --> src/main.rs:28:8 | 13 | impl Dijkstra { | ------------- methods in this implementation ... 28 | fn get_cost(&self, idx: usize) -> usize { | ^^^^^^^^ ... 49 | fn reconstruct(&self, startpoint: usize, endpoint: usize) -> Vec<(usize, usize)> { | ^^^^^^^^^^^
ソースコード
use std::{cmp::Reverse, collections::BinaryHeap}; const INF: usize = 1usize << 60; #[derive(Debug, Clone)] struct Dijkstra { n: usize, pathcosts: Vec<Vec<(usize, usize)>>, pathcostsrev: Vec<Vec<(usize, usize)>>, costs: Vec<usize> } impl Dijkstra { fn new(n: usize) -> Self { Self { n: n , pathcosts: vec![vec![]; n] , pathcostsrev: vec![vec![]; n] , costs: vec![INF; n] } } fn pusha2b(&mut self, a: usize, b: usize, cost: usize) { self.pathcosts[a].push((cost, b)); self.pathcostsrev[b].push((cost, a)); } fn get_cost(&self, idx: usize) -> usize { self.costs[idx] } fn solve(&mut self, startpoint: usize) { let mut que = BinaryHeap::new(); que.push(Reverse((0, startpoint))); self.costs[startpoint] = 0; while let Some(Reverse(p)) = que.pop() { let cost = p.0; let dest = p.1; if cost > self.costs[dest] { continue; } for &p2 in self.pathcosts[dest].iter() { if self.costs[dest] + p2.0 < self.costs[p2.1] { self.costs[p2.1] = self.costs[dest] + p2.0; que.push(Reverse((self.costs[p2.1], p2.1))); } } } } fn reconstruct(&self, startpoint: usize, endpoint: usize) -> Vec<(usize, usize)> { let mut ret = vec![]; if self.costs[endpoint] == INF { return ret; } let mut current = endpoint; while current != startpoint { for &(cost, u) in self.pathcostsrev[current].iter() { if self.costs[current] == self.costs[u] + cost { let prev = current; current = u; ret.push((current, prev)); break; } } } ret.reverse(); ret } } 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::with_capacity(m); 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.push((u, v, c)); } let mut lower = 0usize; let mut upper = 200001; while upper > lower { let middle = (upper + lower) / 2; let mut dijkstra = Dijkstra::new(n); for &(u, v, c) in paths.iter() { dijkstra.pusha2b(u, v, if c > middle { 1 } else { 0 }); dijkstra.pusha2b(v, u, if c > middle { 1 } else { 0 }); } dijkstra.solve(0); if dijkstra.costs[n-1] < k { upper = middle; } else { lower = middle + 1; } } println!("{}", upper); }