我的思路:
对于每一只奶龙都以其为起点构建一条长度为 k+1 的链,链的后面是没有奶龙的结点。根据有解判定可知 m(k+1)≥n,所以这些链一定能在 k 步时覆盖所有没有奶龙的点。现在我们得到 m 条散链,为了凑够边数,考虑把每条链都连回 a1。
经过评测尝试, 为什么一定要连回 a1,其他的都不行?求教
部分ac code:
vector<int> to(n + 1, 0);
vector<bool> vis(n + 1, 0);
for(int i = 1; i <= m; i ++){
vis[a[i]] = true;
}
int now = 1;
for(int i = 1; i <= m; i ++){
int s = a[i];
for(int j = 1; j <= k && now <= n; ){
if(!vis[now]){
to[s] = now;
s = now;
j ++;
}
now ++;
}
to[s] = a[1];
}
for(int i = 1; i <= n; i ++){
cout << i << ' ' << to[i] << '\n';
}