Submission #6071438


Source Code Expand

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define all(v) v.begin(),v.end()
#define make_unique(v) v.erase(unique(all(v),v.end()))
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define dbg(x);
#define dbgv(v);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa
#ifdef ALEXPC
#define dbg(x); cout<<#x<<" = "<<x<<endl
#define dbgv(v); cout<<#v<<" = ["; trav(tv,v)cout<<"tv,";cout<<"]"<<endl
#endif

//const int N=100,M=N*N;
const ll MOD=1000*1000*1000+7;

const int N=1e5+6;

vector<int> g[2*N];
ll qan1[2*N],qan2[2*N];
bool col[2*N];
void dfs(int v,int comp){
    if (v>N) qan1[comp]++;
    else qan2[comp]++;
    col[v]=true;
    trav(to,g[v]){
        if (!col[to])dfs(to,comp);
    }
}

int main(){
    fastio;
    srng;
    int n,k;
    cin>>n>>k;
    if (k>(n-1)*(n-2)/2){
        cout<<-1<<endl;
        return 0;
    }
    vector<pir> pat;
    FORT(i,2,n){
        pat.ad({1,i});
    }
    int qan=(n-1)*(n-2)/2;
    while(qan!=k){
        FORT(i,2,n){
            FORT(j,i+1,n){
                pat.ad({i,j});
                qan--;
                if (qan==k)break;
            }
            if (qan==k)break;
        }
    }
    cout<<pat.size()<<endl;
    trav(tv,pat){
        cout<<tv.fr<<" "<<tv.sc<<endl;
    }
    return 0;
}

Submission Info

Submission Time
Task E - Friendships
User Abelyan
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1850 Byte
Status AC
Exec Time 11 ms
Memory 6400 KB

Judge Result

Set Name All Sample
Score / Max Score 500 / 500 0 / 0
Status
AC × 18
AC × 2
Set Name Test Cases
All sample_01, sample_02, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16
Sample sample_01, sample_02
Case Name Status Exec Time Memory
sample_01 AC 4 ms 6272 KB
sample_02 AC 4 ms 6272 KB
testcase_01 AC 4 ms 6272 KB
testcase_02 AC 4 ms 6272 KB
testcase_03 AC 4 ms 6272 KB
testcase_04 AC 11 ms 6400 KB
testcase_05 AC 4 ms 6272 KB
testcase_06 AC 4 ms 6272 KB
testcase_07 AC 4 ms 6272 KB
testcase_08 AC 4 ms 6272 KB
testcase_09 AC 4 ms 6272 KB
testcase_10 AC 4 ms 6272 KB
testcase_11 AC 4 ms 6272 KB
testcase_12 AC 3 ms 6272 KB
testcase_13 AC 4 ms 6272 KB
testcase_14 AC 4 ms 6272 KB
testcase_15 AC 11 ms 6400 KB
testcase_16 AC 4 ms 6272 KB