题解 | 小红的树构造
小红的树构造
https://www.nowcoder.com/practice/5229e7a68b5a4a2381341ffa4f832273
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll n,k;
cin>>n>>k;
if(k>n-1){
cout<<-1;
}
else if(k==1){
if(n==2)cout<<1<<' '<<2;
else cout<<-1;
}
else{
for(ll i=1;i<=k;i++){
cout<<i<<' '<<i+1<<'\n';
}
for(ll i=k+2;i<=n;i++){
cout<<2<<' '<<i<<'\n';
}
}
return 0;
}
查看18道真题和解析