結果

問題 No.408 五輪ピック
ユーザー phspls
提出日時 2023-01-14 03:33:48
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,392 bytes
コンパイル時間 14,982 ms
コンパイル使用メモリ 378,828 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-12-25 00:28:23
合計ジャッジ時間 17,250 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::collections::HashMap`
 --> src/main.rs:1:5
  |
1 | use std::collections::HashMap;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::collections::HashMap;


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

    let mut mapping = vec![vec![]; n];
    for &u in paths[0].iter() {
        for &v in paths[u].iter() {
            mapping[v].push(u);
        }
    }
    for i in 0..n {
        if mapping[i].is_empty() { continue; }
        for j in i+1..n {
            if mapping[j].is_empty() { continue; }
            if mapping[i].len() > 2 && mapping[j].len() > 2 {
                println!("YES");
                return;
            } else {
                for &k in mapping[i].iter() {
                    for &l in mapping[j].iter() {
                        if k != j && k != l && l != i {
                            println!("YES");
                            return;
                        }
                    }
                }
            }
        }
    }
    println!("NO");
}
0