1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
//Jakub Nowak XIV LO Wroclaw
#include<bits/stdc++.h>
using namespace std;

#define boost ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define st first
#define nd second

void wypisz(auto &X) {
    for(auto &x : X) cout << x << " ";
    cout << "\n";
}

struct ruch{
    bool czy_dodajemy;
    int a, b;
};

vector<ruch> ad_astra(const auto &V, const auto &E) {
    vector<ruch> ANS(1, {false, 0, 0});

    {//Dodawanie
        vector<bool> BEEN(V.size(), false);

        function<void(int)> dfs = [&](int v) {
            //BEEN[v] = true;

            for(auto &u : V[v]) {
                if(BEEN[u]) continue;
                ANS.pb({true, 1, u});//tylko jesli nie bylo wczesniej krawedzi (1, u)
                BEEN[u] = true;
                dfs(u);
            }
        };

        BEEN[1] = true;
        for(auto &u : V[1]) BEEN[u] = true;
        //dfs(1);
        for(auto &u : V[1]) dfs(u);
    }

    {//Usuwanie
        for(auto &u : E) {
            if(u.st != 1 && u.nd != 1) ANS.pb({false, u.st, u.nd});
        }
    }

    return ANS;
}

void solve() {
    int n, m1, m2;
    vector<vi> V1(1, vi(0));
    vector<vi> V2(1, vi(0));
    vector<pii> E1(0);
    vector<pii> E2(0);

    cin >> n;
    V1 = vector<vi>(n+1, vi(0));
    V2 = vector<vi>(n+1, vi(0));
    
    cin >> m1;
    for(int i=1; i<=m1; i++) {
        int a, b;
        cin >> a >> b;
        E1.pb({a,b});
        V1[a].pb(b);
        V1[b].pb(a);
    }

    cin >> m2;
    for(int i=1; i<=m2; i++) {
        int a, b;
        cin >> a >> b;
        E2.pb({a,b});
        V2[a].pb(b);
        V2[b].pb(a);
    }

    vector<ruch> ANS1 = ad_astra(V1, E1);
    vector<ruch> ANS2 = ad_astra(V2, E2);

    cout << ANS1.size() + ANS2.size() -2 << "\n";
    for(int i = 1; i<ANS1.size(); i++) {
        auto &r = ANS1[i];
        if(r.czy_dodajemy) cout << "+ ";
        else cout << "- ";
        cout << r.a << " " << r.b << "\n";
    }
    for(int i = ANS2.size()-1; i>=1; i--) {
        auto &r = ANS2[i];
        if(!r.czy_dodajemy) cout << "+ ";
        else cout << "- ";
        cout << r.a << " " << r.b << "\n";
    }
}

int32_t main() {
    boost
    solve();
}