結果

問題 No.408 五輪ピック
ユーザー phsplsphspls
提出日時 2023-01-12 18:52:33
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,137 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 143,436 KB
実行使用メモリ 8,092 KB
最終ジャッジ日時 2023-08-25 00:42:04
合計ジャッジ時間 7,995 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 11 ms
4,384 KB
testcase_06 WA -
testcase_07 AC 12 ms
4,384 KB
testcase_08 AC 10 ms
4,388 KB
testcase_09 AC 10 ms
4,384 KB
testcase_10 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

fn dfs(cur: usize, paths: &Vec<Vec<usize>>, cnt: &mut usize, checked: &mut Vec<bool>) -> bool {
    if checked[cur] {
        return cur == 0 && *cnt >= 5;
    }
    checked[cur] = true;
    *cnt += 1;
    for &v in paths[cur].iter() {
        if dfs(v, &paths, cnt, checked) {
            return true;
        }
    }
    checked[cur] = false;
    *cnt -= 1;
    false
}

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    let mut paths = vec![vec![]; n];
    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 a = temp[0]-1;
        let b = temp[1]-1;
        paths[a].push(b);
        paths[b].push(a);
    }

    let mut checked = vec![false; n];
    let mut cnt = 0usize;
    if dfs(0, &paths, &mut cnt, &mut checked) {
        println!("YES");
    } else {
        println!("NO");
    }
}
0