1 #include <iostream> 2 #include <vector> 3 4 using namespace std; 5 6 int main(){ 7 int n,m; 8 cin >> n >> m; 9 vector< bool > flag(n+1,false); 10 for(int i = 0 ; i < m ; i ++ ){ 11 int a,b; 12 cin >> a>>b; 13 flag[a]=flag[b]=true; 14 } 15 int centerPoint = 0; 16 for(int i = 1 ; i <= n ; i ++ ){ 17 if(!flag[i]){ 18 centerPoint = i; 19 break; 20 } 21 } 22 cout<<n-1<<endl; 23 for(int i = 1; i <= n ; i ++ ){ 24 if(i!=centerPoint) cout<<i<<" "<<centerPoint<<endl; 25 } 26 return 0; 27 }
主要思路:就是一个中心点,其余的点都挂在上面