結果

問題 No.2674 k-Walk on Bipartite
ユーザー ngtkanangtkana
提出日時 2024-03-02 03:42:30
言語 Rust
(1.77.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,985 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 192,708 KB
実行使用メモリ 15,996 KB
最終ジャッジ日時 2024-03-13 19:34:09
合計ジャッジ時間 3,934 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
6,548 KB
testcase_07 AC 75 ms
13,096 KB
testcase_08 AC 93 ms
11,264 KB
testcase_09 AC 59 ms
13,004 KB
testcase_10 AC 108 ms
13,080 KB
testcase_11 AC 66 ms
10,888 KB
testcase_12 AC 105 ms
11,904 KB
testcase_13 AC 52 ms
11,696 KB
testcase_14 AC 14 ms
7,900 KB
testcase_15 AC 138 ms
14,240 KB
testcase_16 AC 91 ms
13,988 KB
testcase_17 AC 85 ms
10,880 KB
testcase_18 AC 31 ms
8,704 KB
testcase_19 AC 65 ms
12,520 KB
testcase_20 AC 56 ms
12,760 KB
testcase_21 AC 83 ms
11,904 KB
testcase_22 AC 135 ms
15,996 KB
testcase_23 AC 1 ms
6,548 KB
testcase_24 AC 1 ms
6,548 KB
testcase_25 AC 1 ms
6,548 KB
testcase_26 AC 1 ms
6,548 KB
testcase_27 AC 1 ms
6,548 KB
testcase_28 AC 1 ms
6,548 KB
testcase_29 AC 1 ms
6,548 KB
testcase_30 AC 1 ms
6,548 KB
testcase_31 AC 1 ms
6,548 KB
testcase_32 AC 1 ms
6,548 KB
testcase_33 AC 1 ms
6,548 KB
testcase_34 AC 1 ms
6,548 KB
testcase_35 AC 1 ms
6,548 KB
testcase_36 AC 1 ms
6,548 KB
testcase_37 AC 1 ms
6,548 KB
testcase_38 AC 1 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use input::input_array;
use std::collections::VecDeque;
use Ans::*;

fn main() {
    let [n, m] = input_array::<usize, 2>();
    let [start, end, k] = input_array::<usize, 3>();
    let start = start - 1;
    let end = end - 1;
    let mut g = vec![Vec::new(); n];
    for _ in 0..m {
        let [i, j] = input_array::<usize, 2>();
        let i = i - 1;
        let j = j - 1;
        g[i].push(j);
        g[j].push(i);
    }
    let mut dist = vec![std::usize::MAX; g.len()];
    dist[start] = 0;
    let mut queue = VecDeque::from(vec![start]);
    while let Some(x) = queue.pop_front() {
        for &y in &g[x] {
            if dist[y] == std::usize::MAX {
                dist[y] = dist[x] + 1;
                queue.push_back(y);
            }
        }
    }
    let d = dist[end];
    let ans = match () {
        () if d == !0 => {
            if n == 2 && k % 2 == 0 {
                No
            } else {
                Unknown
            }
        }
        () if d % 2 != k % 2 => No,
        () if k < d || start == end && g[start].is_empty() => Unknown,
        () => Yes,
    };
    println!(
        "{}",
        match ans {
            Yes => "Yes",
            No => "No",
            Unknown => "Unknown",
        }
    );
}

#[derive(Clone, Copy)]
enum Ans {
    Yes,
    No,
    Unknown,
}

// input {{{
#[allow(dead_code)]
mod input {
    use std::cell::Cell;
    use std::convert::TryFrom;
    use std::io::stdin;
    use std::io::BufRead;
    use std::io::BufReader;
    use std::io::Lines;
    use std::io::Stdin;
    use std::str::FromStr;
    use std::sync::Mutex;
    use std::sync::Once;
    type Server = Mutex<Lines<BufReader<Stdin>>>;
    static ONCE: Once = Once::new();
    pub struct Lazy(Cell<Option<Server>>);
    unsafe impl Sync for Lazy {}
    fn line() -> String {
        static SYNCER: Lazy = Lazy(Cell::new(None));
        ONCE.call_once(|| {
            SYNCER
                .0
                .set(Some(Mutex::new(BufReader::new(stdin()).lines())));
        });
        unsafe {
            (*SYNCER.0.as_ptr())
                .as_ref()
                .unwrap()
                .lock()
                .unwrap()
                .next()
                .unwrap()
                .unwrap()
        }
    }
    pub trait ForceFromStr: FromStr {
        fn force_from_str(s: &str) -> Self;
    }
    impl<T, E> ForceFromStr for T
    where
        T: FromStr<Err = E>,
        E: std::fmt::Debug,
    {
        fn force_from_str(s: &str) -> Self {
            s.parse().unwrap()
        }
    }
    pub fn input_array<T: ForceFromStr, const N: usize>() -> [T; N]
    where
        T: std::fmt::Debug,
    {
        <[_; N]>::try_from(input_vec()).unwrap()
    }
    pub fn input_vec<T: ForceFromStr>() -> Vec<T> {
        line()
            .split_whitespace()
            .map(T::force_from_str)
            .collect::<Vec<_>>()
    }
    pub fn input<T: ForceFromStr>() -> T {
        T::force_from_str(&line())
    }
}
// }}}
0