結果

問題 No.630 門松グラフ
ユーザー tottoripapertottoripaper
提出日時 2018-01-06 01:31:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 1,500 ms
コード長 1,677 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 172,996 KB
実行使用メモリ 8,508 KB
最終ジャッジ日時 2023-08-24 21:22:23
合計ジャッジ時間 5,888 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 170 ms
8,508 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 171 ms
8,496 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 164 ms
8,072 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 165 ms
8,068 KB
testcase_27 AC 163 ms
8,224 KB
testcase_28 AC 166 ms
8,272 KB
testcase_29 AC 144 ms
7,692 KB
testcase_30 AC 163 ms
8,204 KB
testcase_31 AC 146 ms
7,728 KB
testcase_32 AC 78 ms
5,696 KB
testcase_33 AC 78 ms
5,620 KB
testcase_34 AC 119 ms
6,900 KB
testcase_35 AC 91 ms
6,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, M;
int values[100100];
set<P> edges;

void addEdge(int u, int v){
    edges.emplace(min(u, v), max(u, v));
}

bool can(){
    if(M < N - 1){ // 非連結になってしまう
        return false;
    }

    if(M <= 1ll * (N / 2) * ((N + 1) / 2)){
        for(int i=1;i<=N;++i){
            values[i] = i;
            if(edges.size() < M){
                if(i <= N / 2){
                    addEdge(i, N / 2 + i);
                }else if(i < N / 2 * 2){
                    addEdge(i, i - N / 2 + 1);
                }
            }
        }
        if(N % 2 == 1){
            addEdge(1, N);
        }

        for(int i=1;edges.size()<M&&i<=N/2;++i){
            for(int j=1;edges.size()<M&&j<=(N+1)/2;++j){
                addEdge(i, N / 2 + j);
            }
        }

        return true;
    }

    // 三角形ができてしまうので残念
    return false;
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> M;

    if(can()){
        std::cout << "YES" << std::endl;
        for(int i=1;i<=N;++i){
            std::cout << values[i] << " \n"[i==N];
        }

        for(const auto& p : edges){
            int u, v;
            tie(u, v) = p;

            std::cout << u << " " << v << std::endl;
        }
    }else{
        std::cout << "NO" << std::endl;
    }
}
0