結果
| 問題 |
No.1473 おでぶなおばけさん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-15 03:24:30 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,637 bytes |
| コンパイル時間 | 12,625 ms |
| コンパイル使用メモリ | 401,512 KB |
| 実行使用メモリ | 12,160 KB |
| 最終ジャッジ日時 | 2024-07-01 01:59:11 |
| 合計ジャッジ時間 | 17,086 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 WA * 37 |
ソースコード
#![allow(clippy::many_single_char_names)]
use std::cmp::Reverse;
use std::collections::BinaryHeap;
use std::io::Read as _;
macro_rules! chmax {
($xmax:expr, $x:expr) => {{
if $xmax < $x {
$xmax = $x;
true
} else {
false
}
}};
}
fn solve(n: usize, graph: &[Vec<(usize, u32)>]) -> (u32, u32) {
let mut bests = vec![(0, Reverse(u32::MAX)); n];
let mut que = BinaryHeap::new();
bests[0] = (u32::MAX, Reverse(0));
que.push((u32::MAX, Reverse(0), 0));
while !que.is_empty() {
let (w, Reverse(k), s) = que.pop().unwrap();
if (w, Reverse(k)) < bests[s] {
continue;
}
for &(t, d) in &graph[s] {
let w_new = w.min(d);
let k_new = k + 1;
if chmax!(bests[t], (w_new, Reverse(k_new))) {
que.push((w_new, Reverse(k_new), t));
}
}
}
let (ans_w, Reverse(ans_k)) = bests[n - 1];
(ans_w, ans_k)
}
fn main() {
let mut input = String::new();
std::io::stdin().read_to_string(&mut input).unwrap();
let mut tokens = input.split_ascii_whitespace();
macro_rules! read {
($ty:ty) => {{
tokens.next().unwrap().parse::<$ty>().unwrap()
}};
}
let n = read!(usize);
let m = read!(usize);
let mut graph: Vec<Vec<(usize, u32)>> = vec![vec![]; n];
for _ in 0..m {
let s = read!(usize) - 1;
let t = read!(usize) - 1;
let d = read!(u32);
graph[s].push((t, d));
}
let (ans_w, ans_k) = solve(n, &graph);
println!("{} {}", ans_w, ans_k);
}