結果

問題 No.630 門松グラフ
ユーザー hatoohatoo
提出日時 2018-01-12 17:23:02
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,288 bytes
コンパイル時間 6,460 ms
コンパイル使用メモリ 153,468 KB
実行使用メモリ 349,196 KB
最終ジャッジ日時 2023-08-25 15:38:25
合計ジャッジ時間 12,280 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,752 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,500 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 0 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 MLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;
mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }

fn main() {
    let (n, m) = get!(usize, usize);

    if m >= (n - 1) && m <= (n / 2) * ((n + 1) / 2) {
        let mut g = vec![BTreeSet::new(); n];

        for i in 0..n / 2 {
            g[i].insert(n / 2);
            g[n / 2].insert(i);
        }

        for i in n / 2 + 1..n {
            g[i].insert(0);
            g[0].insert(i);
        }

        let mut rest = m - (n - 1);
        'outer: for i in 0..n / 2 {
            for j in n / 2..n {
                if !g[i].contains(&j) {
                    g[i].insert(j);
                    g[j].insert(i);
                    rest -= 1;
                    if rest == 0 {
                        break 'outer;
                    }
                }
            }
        }

        let e = g.iter()
            .enumerate()
            .flat_map(|(i, set)| {
                set.into_iter()
                    .map(|&j| (min(i, j), max(i, j)))
                    .collect::<Vec<_>>()
            })
            .collect::<BTreeSet<_>>();

        println!("YES");
        println!(
            "{}",
            (1..n + 1)
                .map(|i| i.to_string())
                .collect::<Vec<_>>()
                .join(" ")
        );

        for &(f, t) in &e {
            println!("{} {}", f + 1, t + 1);
        }
    } else {
        println!("NO");
    }
}
0