Solution-P13564
先判无解的情况。显然每只奶龙最多经过
然后考虑构造。我们先标记上所有初始时有奶龙的点,然后对于每只奶龙,找到
于是现在除了每条链的末尾(单个点的末尾即本身)的点的出度均为
代码展示:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k,a[1000001],u,siz,cnt=1;
bool b[1000001];
signed main(){
cin.tie(nullptr)->sync_with_stdio(0);
cin>>n>>m>>k;
for(int i=1;i<=m;i++){
cin>>a[i];
}
if(n>m*(k+1)||n-m<k){
cout<<"-1";
}
else{
for(int i=1;i<=m;i++){
b[a[i]]=true;
}
for(int i=1;i<=m;i++){
siz=0;
u=a[i];
while(siz<=k-1&&cnt<=n){//按照编号顺次枚举,选了超过k个点或没法选足够的点就退出
if(!b[cnt]){
cout<<u<<' '<<cnt<<'\n';
u=cnt;
siz++;
}
cnt++;
}
cout<<u<<' '<<a[1]<<'\n';
}
}
return 0;
}