题目链接:Codeforces 330B Road Construction
m < n / 2,所以必然有一个节点与所有边都相连(画出来的。。),所以边数就是n - 1。
#include<iostream>
#include <cstring>
using namespace std;
bool e[1001];
int main(){
int n,m;
int x,y;
memset(e,0,sizeof(e));
cin >> n >> m;
int i;
for (i = 0; i < m; i++)
{
cin >> x >> y;
e[x] = e[y] = true;
}
for (i = 1; i <= n; i++)
if (!e[i])
break;
cout << n -1 << endl;
for (int j = 1; j <= n; j++)
if (i != j) cout << j << " " << i <<endl;
}
本文提供了一个解决Codeforces330B问题的简洁算法实现方案,通过确定一个中心节点并输出所有可能的边来构造解决方案。该算法利用了m<n/2的条件,确保了解决方案的有效性。
586

被折叠的 条评论
为什么被折叠?



