結果

問題 No.2910 単体ホモロジー入門
ユーザー atcoder8
提出日時 2024-10-04 22:39:59
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 14,451 ms
コンパイル使用メモリ 383,528 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-04 22:40:15
合計ジャッジ時間 14,698 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

fn main() {
    println!("{}", if solve() { "Yes" } else { "No" });
}

fn solve() -> bool {
    input! {
        (n, m): (usize, usize),
        ij: [(usize, usize); m],
        mut vv: [usize; 3],
    }

    vv.sort_unstable();
    vv.dedup();

    let mut graph = vec![vec![]; n];
    for &(u, v) in &ij {
        graph[u].push(v);
        graph[v].push(u);
    }

    let mut stack = (0..n).map(|i| vec![i]).collect::<Vec<_>>();
    while let Some(path) = stack.pop() {
        let cur = *path.last().unwrap();
        for &next in &graph[cur] {
            if path.len() >= 3 && next == path[0] {
                let mut nodes = path.clone();
                nodes.sort_unstable();
                nodes.dedup();

                if nodes != vv {
                    return true;
                }

                continue;
            }

            if path.contains(&next) {
                continue;
            }

            let mut next_path = path.clone();
            next_path.push(next);
            stack.push(next_path);
        }
    }

    false
}
0