結果

問題 No.630 門松グラフ
ユーザー sinsincoscos
提出日時 2019-03-14 22:14:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,126 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 88,420 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-06-27 05:58:36
合計ジャッジ時間 4,527 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 6 WA * 2 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
ll N,M;
int A[100010];
vector<pair<int,int>> ans;
int main(){
    cin >> N >> M;
    if(M<N-1){
        cout << "NO" << endl;
        return 0;
    }
    ll k = (N+1)/2;
    if((k%2==0 && k*k<M) || (k%2==1 && k*(k-1)<M)){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    for(int i=1;i<=N;i++){
        cout << i << (i!=N? " ":"\n");
    }
    map<pair<int,int>,int> m;
    for(int i=1;i<=k;i++){
        if(!(N%2==1 && i==k)){
            ans.push_back({i,i+k});
            m[{i,i+k}]++;
        }
        if(i!=1){
            ans.push_back({i,i+k-1});
            m[{i,i+k-1}]++;
        }
    }
    M -= N-1;
    int s_id = 1,b_id = k+2;
    while(M>0){
        int a = s_id,b = b_id;
        if(a>b) swap(a,b);
        if(m.count({a,b})) continue;
        ans.push_back({a,b});
        m[{a,b}]++;
        M--;
        b_id++;
        if(b_id>N){
            s_id++;
            b_id = k+2;
        }
    }
    for(auto x:ans) cout << x.first << " " << x.second << endl;
}
0