結果
問題 | No.1190 Points |
ユーザー | fukafukatani |
提出日時 | 2020-08-23 15:57:36 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 326 ms / 2,000 ms |
コード長 | 3,299 bytes |
コンパイル時間 | 13,245 ms |
コンパイル使用メモリ | 378,800 KB |
実行使用メモリ | 25,984 KB |
最終ジャッジ日時 | 2024-10-15 18:42:25 |
合計ジャッジ時間 | 20,197 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 145 ms
19,328 KB |
testcase_04 | AC | 102 ms
17,536 KB |
testcase_05 | AC | 144 ms
16,000 KB |
testcase_06 | AC | 144 ms
23,936 KB |
testcase_07 | AC | 219 ms
25,728 KB |
testcase_08 | AC | 260 ms
25,984 KB |
testcase_09 | AC | 246 ms
23,664 KB |
testcase_10 | AC | 261 ms
25,984 KB |
testcase_11 | AC | 173 ms
17,472 KB |
testcase_12 | AC | 237 ms
25,216 KB |
testcase_13 | AC | 174 ms
14,856 KB |
testcase_14 | AC | 26 ms
12,800 KB |
testcase_15 | AC | 305 ms
24,360 KB |
testcase_16 | AC | 15 ms
6,016 KB |
testcase_17 | AC | 261 ms
23,108 KB |
testcase_18 | AC | 101 ms
11,816 KB |
testcase_19 | AC | 21 ms
13,440 KB |
testcase_20 | AC | 144 ms
13,832 KB |
testcase_21 | AC | 43 ms
11,520 KB |
testcase_22 | AC | 47 ms
18,304 KB |
testcase_23 | AC | 326 ms
24,964 KB |
testcase_24 | AC | 318 ms
25,044 KB |
testcase_25 | AC | 146 ms
24,320 KB |
testcase_26 | AC | 107 ms
23,808 KB |
testcase_27 | AC | 163 ms
24,576 KB |
コンパイルメッセージ
warning: unused variable: `i` --> src/main.rs:31:9 | 31 | for i in 0..m { | ^ help: if this is intentional, prefix it with an underscore: `_i` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn to_index(idx: usize, res: usize) -> usize { res + idx * 2 } fn main() { let v = read_vec::<i64>(); let (n, m, p) = (v[0] as usize, v[1] as usize, v[2]); //let p = min(p, 1000000 + p % 2) as usize; let v = read_vec::<usize>(); let (s, g) = (v[0] - 1, v[1] - 1); let mut edges = vec![vec![]; 2 * n]; for i in 0..m { let v = read_vec::<usize>(); let (u, v) = (v[0] - 1, v[1] - 1); edges[to_index(u, 0)].push(Edge { to: to_index(v, 1), cost: 1, }); edges[to_index(v, 0)].push(Edge { to: to_index(u, 1), cost: 1, }); edges[to_index(u, 1)].push(Edge { to: to_index(v, 0), cost: 1, }); edges[to_index(v, 1)].push(Edge { to: to_index(u, 0), cost: 1, }); } let from_s = solve(&edges, to_index(s, 0)); let from_g = solve(&edges, to_index(g, 0)); if from_s[to_index(g, p as usize % 2)] > p { println!("-1"); return; } let mut answers = vec![]; for i in 0..n { if from_s[to_index(i, 0)] + from_g[to_index(i, p as usize % 2)] <= p { answers.push(i); } else if from_s[to_index(i, 1)] + from_g[to_index(i, 1 - (p as usize % 2))] <= p { answers.push(i); } } println!("{}", answers.len()); for ans in answers { println!("{}", ans + 1); } } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } use std::cmp::Ordering; use std::collections::BinaryHeap; const INF: i64 = 100000_00000_00000; #[derive(PartialEq, Debug)] struct MinInt { value: i64, } impl Eq for MinInt {} impl PartialOrd for MinInt { fn partial_cmp(&self, other: &Self) -> Option<Ordering> { other.value.partial_cmp(&self.value) } } impl Ord for MinInt { fn cmp(&self, other: &MinInt) -> Ordering { other.value.cmp(&self.value) } } fn make_pair(x: i64, y: usize) -> (MinInt, usize) { (MinInt { value: x }, y) } #[derive(Debug, Clone)] struct Edge { to: usize, cost: i64, } fn solve(edges: &Vec<Vec<Edge>>, start_idx: usize) -> Vec<i64> { let num_apexes = edges.len(); let mut d = vec![INF; num_apexes]; d[start_idx] = 0; let mut que = BinaryHeap::new(); que.push(make_pair(0, start_idx)); while let Some((u, v)) = que.pop() { if d[v] < u.value { continue; } for e in &edges[v] { if d[v] != INF && d[e.to] > d[v] + e.cost { d[e.to] = d[v] + e.cost; que.push(make_pair(d[e.to], e.to)); } } } d }