結果
問題 | No.630 門松グラフ |
ユーザー |
|
提出日時 | 2018-01-05 22:51:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 1,500 ms |
コード長 | 1,102 bytes |
コンパイル時間 | 597 ms |
コンパイル使用メモリ | 67,192 KB |
最終ジャッジ日時 | 2025-01-05 07:04:59 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <iostream> using namespace std; int n,m; int a[100100]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; int x = (n + 1) / 2; int y = n - x; if (n - 1 <= m && m <= 1ll * x * y) { cout << "YES" << '\n'; int num = 1; for (int i = 0; i < n; i += 2) { a[i] = num++; } for (int i = 1; i < n; i += 2) { a[i] = num++; } for (int i = 0; i < n; i++) { cout << a[i] << (i < n - 1 ? ' ' : '\n'); } for (int i = 0; i < n - 1; i++) { cout << i+1 << ' ' << i+2 << '\n'; } m -= n - 1; for (int i = 0; i < n; i += 2) { for (int j = 1; j < n; j += 2) { if (!m) return 0; if (abs(i - j) > 1) { cout << i+1 << ' ' << j+1 << '\n'; m--; } } } } else { cout << "NO" << '\n'; } return 0; }