結果
問題 |
No.630 門松グラフ
|
ユーザー |
![]() |
提出日時 | 2018-01-06 01:17:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,550 bytes |
コンパイル時間 | 1,798 ms |
コンパイル使用メモリ | 175,132 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-12-23 07:25:18 |
合計ジャッジ時間 | 7,771 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 15 WA * 17 |
ソースコード
#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; bool can(){ if(M < N - 1){ // 非連結になってしまう return false; } if(M <= (N / 2) * ((N + 1) / 2)){ for(int i=1;i<=N;++i){ values[i] = i; if(edges.size() < M){ if(i <= N / 2){ edges.emplace(i, N / 2 + i); }else{ edges.emplace(i, i < N ? i - N / 2 + 1 : 1); } } } for(int i=1;edges.size()<M&&i<=N/2;++i){ for(int j=1;edges.size()<M&&j<=(N+1)/2;++j){ edges.emplace(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; } }