fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8.  
  9. int n, m;
  10. cin >> n >> m;
  11. if (n == 1) {
  12. cout << "NO\n";
  13. exit(0);
  14. }
  15. cout << "YES\n";
  16. unordered_set<string> st;
  17. st.reserve(m * 2);
  18.  
  19. auto frmat = [](int a, int b) {
  20. return to_string(min(a, b)) + "-" + to_string(max(a, b));
  21. };
  22.  
  23. for (int i = 0; i < m; i++) {
  24. int a, b;
  25. cin >> a >> b;
  26. st.insert(frmat(a, b));
  27. }
  28.  
  29. int half = n / 2;
  30. for (int i = 1; i <= half; i++) {
  31. for (int j = i + 1; j <= half; j++) {
  32. string edge = frmat(i, j);
  33. if (!st.count(edge)) {
  34. cout << i << ' ' << j << '\n';
  35. }
  36. }
  37. }
  38. for (int i = half + 1; i <= n; i++) {
  39. for (int j = i + 1; j <= n; j++) {
  40. string edge = frmat(i, j);
  41. if (!st.count(edge)) {
  42. cout << i << ' ' << j << '\n';
  43. }
  44. }
  45. }
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
YES