#include <bits/stdc++.h>
using namespace std;

//toast418
#define ffor(i,o,f)		   for(int i = o; i < f; i++)
#define pb 				   push_back
#define mp                 make_pair
#define all(a)             (a).begin(), (a).end()
#define F                  first
#define S                  second
#define PI 				   3.14159265358979323846264338327950
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl 			   '\n'
#define sz(x)              ((int)(x).size())
typedef long long          ll;
typedef pair < int, int >  pii;
typedef vector < int >     vi;
typedef vector < pii >     vii;
typedef vector < vi > 	   gi;
typedef vector < ll >      vll;
typedef map < int, int >   mii;

int t, n, m, u, v, groups;
const int tam = 1005;
vi parent;
vi componentSize;
vii edges;
vii addedEdges;

int find(int nd){
    if(parent[nd] == nd){
        return nd;
    }
    return parent[nd] = find(parent[nd]);
}

void unite(int nd1, int nd2){
    nd1 = find(nd1);
    nd2 = find(nd2);
    if(nd1 == nd2){
        return;
    }
    if(componentSize[nd1] < componentSize[nd2]){
        swap(nd1, nd2);
    }
    parent[nd2] = nd1;
    componentSize[nd1] += componentSize[nd2];
}

void query(int nd1, int nd2){
    if(find(nd1) == find(nd2)){
        cout << "SI, la componente tiene "
             << componentSize[find(nd1)] << " nodos" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

void connectGraph(){
    vi representatives;
    ffor(i, 0, 10){
        if(find(i) == i){
            representatives.pb(i);
        }
    }
    ffor(i, 1, sz(representatives)){
        int nd1 = representatives[i - 1];
        int nd2 = representatives[i];
        if(find(nd1) != find(nd2)){
            addedEdges.pb(mp(nd1, nd2));
            unite(nd1, nd2);
        }
    }
}

int main()
{
    parent.assign(tam, 0);
    componentSize.assign(tam, 1);
    ffor(i, 0, tam){
        parent[i] = i;
    }

    edges.pb(mp(0, 3));
    edges.pb(mp(0, 5));
    edges.pb(mp(3, 6));
    edges.pb(mp(5, 6));
    edges.pb(mp(1, 4));
    edges.pb(mp(4, 8));
    edges.pb(mp(2, 7));

    ffor(i, 0, sz(edges)){
        unite(edges[i].F, edges[i].S);
    }

    query(5, 3);
    query(1, 8);
    query(6, 7);
    query(9, 9);

    connectGraph();

    cout << "Se necesitan " << sz(addedEdges)
         << " aristas para conectar todo el grafo:" << endl;
    ffor(i, 0, sz(addedEdges)){
        cout << addedEdges[i].F << "-" << addedEdges[i].S << endl;
    }
}
