题解 | 小红的树构造

小红的树构造

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;
}



全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务