結果

問題 No.630 門松グラフ
ユーザー hatoohatoo
提出日時 2018-01-12 17:24:24
言語 Rust
(1.77.0)
結果
AC  
実行時間 193 ms / 1,500 ms
コード長 3,369 bytes
コンパイル時間 2,360 ms
コンパイル使用メモリ 166,584 KB
実行使用メモリ 25,228 KB
最終ジャッジ日時 2023-08-25 15:46:18
合計ジャッジ時間 7,263 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
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 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 190 ms
25,228 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 193 ms
24,996 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 167 ms
10,852 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 168 ms
10,968 KB
testcase_27 AC 168 ms
12,448 KB
testcase_28 AC 186 ms
23,920 KB
testcase_29 AC 164 ms
20,380 KB
testcase_30 AC 184 ms
17,064 KB
testcase_31 AC 165 ms
14,036 KB
testcase_32 AC 87 ms
11,480 KB
testcase_33 AC 82 ms
7,120 KB
testcase_34 AC 130 ms
11,092 KB
testcase_35 AC 93 ms
7,368 KB
権限があれば一括ダウンロードができます

ソースコード

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);
        if rest != 0 {
            '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