constructive algorithms trees *1500

Please click on ads to support us..

Python Code:

import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

n = int(input())
ans = []
if n <= 5:
    ans0 = "-1"
    ans.append(ans0)
else:
    ans.append("1 2")
    for v in range(3, n + 1):
        u = v % 2 + 1
        ans.append(" ".join(map(str, (u, v))))
for u in range(1, n):
    v = u + 1
    ans.append(" ".join(map(str, (u, v))))
sys.stdout.write("\n".join(ans))

C++ Code:

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;


#define cm ios_base::sync_with_stdio(0);cin.tie(0);

#define pb push_back
#define pp pop_back
#define pii pair<int,int>
#define pr_q(a) priority_queue<a,vector<a>,greater<a>>
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define rep(i,a,n) for(int i=a;i<n;i++)

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
/**
    indexed_set s;
    s.insert(a);
    auto x = s.find_by_order(2); cout<<*x;
    cout<<s.order_of_key(7);
*/

int _last(){return 0;}
int _first(){return 0;}
template<typename T,typename... V>
int _last(T x,V... y){if(sizeof...(y))return max(x,_last(y...));else return x;}
template<typename T,typename... V>
int _first(T x,V... y){if(sizeof...(y))return min(x,_first(y...));else return x;}

void _mx(auto &x,auto... y){
    int val = _last(y...);
    x = (x>val?x:val);
}
void _mn(auto &x,auto... y){
    int val = _first(y...);
    x = (x<val?x:val);
}
const int mod = 1e9+7; /// 998244353
const int N = 1e6+5;
const int inf = 1e9;
const int ff[]={-1,0,1,0,-1};


void solve(){
    int n;cin>>n;
    if(n<=5){
        cout<<"-1\n";
        for(int i=2;i<=n;i++){
            cout<<"1 "<<i<<'\n';
        }
    }else{
        for(int i=2;i<=4;i++){
            cout<<"1 "<<i<<"\n";
        }
        for(int i=5;i<=n;i++){
            cout<<2<<' '<<i<<'\n';
        }
        for(int i=2;i<=n;i++){
            cout<<"1 "<<i<<'\n';
        }
    }
}


signed main(){

    chrono::steady_clock::time_point begin = chrono::steady_clock::now();

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t=1;
//    cin>>t;
    for(int i=1;i<=t;i++){
        solve();
    }
    chrono::steady_clock::time_point end = chrono::steady_clock::now();

    cerr<<"[Time Difference: "<<chrono::duration_cast<chrono::seconds>(end-begin).count()<<"[s]]" << endl;
    cerr<<"[Time Difference: "<<chrono::duration_cast<chrono::milliseconds>(end-begin).count()<<"[ms]]" << endl;

}


Comments

Submit
0 Comments
More Questions

766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament