Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code: The 67th Tree Problem

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long test = 1;
    cin >> test;
    bool submit = true;
    if (test >= 10010010)
        submit = false;
    if (test == 1)
        submit = true;

    while (test--) {
        int X, Y;
        cin >> X >> Y;
        if (X > Y) {
            cout << "NO\n";
            continue;
        }
        int N = X + Y;
        if (N % 2 == 0 && X == 0) {
            cout << "NO\n";
            continue;
        }

        int pos = 0;
        vector<pair<int, int>> answer;
        if (N % 2 == 0)
            X--;
        else
            Y--;
        N--;
        while (X) {
            answer.push_back({pos, pos + 1}), pos++;
            if (N % 2 == 0)
                X--;
            else
                Y--;
            N--;
        }
        int pos2 = pos;
        while (Y--)
            answer.push_back({pos, ++pos2});

        cout << "YES\n";
        for (auto [u, v] : answer)
            cout << u + 1 << " " << v + 1 << "\n";
    }
}