#include using namespace std; int N, M, K; vector> ans; void print_no() { cout << "No\n"; } void print_yes() { cout << "Yes\n"; for (auto [u, v] : ans) { cout << u << ' ' << v << '\n'; } } int main() { cin >> N >> M >> K; int T = N * (N - 1) / 2; if (K == 1) { if (M == T) { print_no(); return 0; } for (int u = 1; u <= N; ++u) { for (int v = u + 1; v <= N; ++v) { if (u == 1 && v == N) continue; if ((int)ans.size() < M) { ans.push_back({u, v}); } } } print_yes(); return 0; } // K >= 2. int max_removed = T - K; // WRONG: // It checks only the upper bound of M. // It forgets the lower bound needed to remove shortcuts. if (M > max_removed) { print_no(); return 0; } // Use the path 1 - 2 - ... - K - N. vector path; path.push_back(1); for (int v = 2; v <= K; ++v) { path.push_back(v); } path.push_back(N); vector> is_path_edge(N + 1, vector(N + 1, false)); for (int i = 0; i + 1 < (int)path.size(); ++i) { int a = path[i]; int b = path[i + 1]; if (a > b) swap(a, b); is_path_edge[a][b] = true; } // Intended distance layer (BFS tree) of each vertex. vector layer(N + 1, -1); layer[1] = 0; for (int i = 1; i <= K - 1; ++i) { layer[i + 1] = i; } layer[N] = K; // Make extra vertices belong to layer 1. for (int v = K + 1; v <= N - 1; ++v) { layer[v] = 1; } vector> removed(N + 1, vector(N + 1, false)); // WRONG: // Instead of first removing all shortcut edges, // this code just removes arbitrary non-path edges. // Therefore, many shortcut edges may remain. for (int u = 1; u <= N && (int)ans.size() < M; ++u) { for (int v = u + 1; v <= N && (int)ans.size() < M; ++v) { if (is_path_edge[u][v]) continue; removed[u][v] = true; ans.push_back({u, v}); } } print_yes(); return 0; }