結果

問題 No.3585 Make Ends Meet (Easy)
コンテスト
ユーザー t98slider
提出日時 2026-07-10 22:54:22
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 17 ms / 2,000 ms
+ 891µs
コード長 1,719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,124 ms
コンパイル使用メモリ 341,336 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-11 01:32:36
合計ジャッジ時間 4,468 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<pair<int,int>> ans;
    array<array<bool,100>,100> B{};
    vector<int> path;
    for(int i = 0; i < k; i++) path.emplace_back(i);
    path.emplace_back(n - 1);
    for(int i = 0; i <= k; i++){
        for(int j = i + 1; j <= k; j++){
            B[path[i]][path[j]] = B[path[j]][path[i]] = true;
            if(j - i >= 2)ans.emplace_back(path[i], path[j]);
        }
    }
    for(int i = k; i + 1 < n; i++){
        for(int j = 3; j <= k; j++){
            B[path[j]][i] = B[i][path[j]] = true;
            ans.emplace_back(path[j], i);
        }
    }
    if(m < ans.size()){
        cout << "No" << endl;
        return 0;
    }
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(!B[i][j]) ans.emplace_back(i, j);
        }
    }
    if(ans.size() < m){
        cout << "No" << endl;
    }else{
        cout << "Yes\n";
        array<array<int,100>,100> C{};
        for(int i = 0; i < n; i++) C[i].fill(1), C[i][i] = 0;
        for(int i = 0; i < m; i++){
            auto [u, v] = ans[i];
            C[u][v] = C[v][u] = 1 << 29;
            cout << u + 1 << ' ' << v + 1 << '\n';
        }
        /*for(int k = 0; k < n; k++){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cerr << C[i][j] << ' ';
            }
            cerr << '\n';
        }*/
    }
}
0