CFR 330 B. Road Construction ( Graph Adhoc )
Problem - 330B - Codeforces
There are n vertices and at most n / 2 - 1 edges. Easy to see that there will be at least one vertex with 0 degree.
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 3; const int MAXM = MAXN / 2; int n, m; int vis[ MAXN ]; void print( int x ){ printf("%d\n", n - 1); for( int i = 1; i <= n; ++i ) if( i != x ) printf("%d %d\n", i, x); } int main(){ scanf("%d%d", &n, &m); for( int i = 0; i < m; ++i ){ int u, v; scanf("%d%d", &u, &v); vis[ u ] = vis[ v ] = 1; } for( int i = 1; i <= n; ++i ) if( !vis[ i ] ){ print( i ); return 0; } assert( false ); return 0; }