Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.0 kB
2
Indexable
Never
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <vector>

using namespace std;

vector <bool> used;
vector <pair<int, int> > s, ans;
vector <vector<int>> x;
int n, k;

void go(int pos) {
    if (pos >= n) {
        bool ok = 1;
        //for (auto [a, b] : s) cout << a << " " << b << endl;
        //cout << endl;
        for (int i = 0; i < k; i++) {
            int L = -1e9, R = 1e9;
            for (auto [a, b] : s) {
                int vala = x[a][i];
                int valb = x[b][i];
                if (vala > valb) swap(vala, valb);
                L = max(L, vala);
                R = min(R, valb);
            }
            if (L > R) {
                ok = 0;
                break;
            }
        }
        if (ok) {
            ans = s;
        }
        return;
    }
    if (used[pos]) go(pos + 1);
    else {
        for (int j = pos + 1; j < n; j++) {
            if (!used[j]) {
                used[j] = true;
                s.push_back({pos, j});
                go(pos + 1);
                s.pop_back();
                used[j] = false;
            }
        }
    }
}

int main()
{
    cin >> n >> k;
    x.resize(n);
    for (int i = 0; i < n; i++) {
        x[i].resize(k);
        for (int j = 0; j < k; j++) cin >> x[i][j];
    }
    used.resize(n);
    for (int i = 0; i < n; i++) used[i] = false;
    go(0);
    if (ans.size() > 0) {
        cout << "YES\n";
        for (auto [a, b] : ans) {
            cout << a + 1 << " " << b + 1 << endl;
        }
    }
    else {
        cout << "NO";
    }
    return 0;
}