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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

#define pb push_back

typedef long long ll;
typedef long double ld;
const int maxN = 1e5 + 10;
int m[2];
int a[2][maxN], b[2][maxN];
int n;
bool used[maxN];
vector<int> g[maxN];
int dist[maxN];
vector<pair<int,int>> go(int tp) {
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        dist[i] = -1;
    }
    for (int i = 0; i < m[tp]; i++) {
        used[i] = false;
        g[a[tp][i]].emplace_back(i);
        g[b[tp][i]].emplace_back(i);
    }
    dist[1] = 0;
    queue<int> q;
    q.push(1);
    vector<pair<int,int>> ans;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int id : g[v]) {
            int u = (a[tp][id] ^ b[tp][id]) ^ v;
            if (dist[u] == -1) {
                used[id] = true;
                dist[u] = dist[v] + 1;
                q.push(u);
                if (v != 1) {
                    ans.emplace_back(1, u);
                    ans.emplace_back(~v, ~u);
                }
            }
        }
    }
    for (int i = 0; i < m[tp]; i++) {
        if (!used[i]) {
            assert(a[tp][i] != 1 && b[tp][i] != 1);
            ans.emplace_back(~a[tp][i], ~b[tp][i]);
        }
    }
    return ans;
}
mt19937 rnd(322);
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    while (true) {
        cin >> n;
//        cout << " ggg1 " << endl;
//        n = 30'000;
//        cout << n << endl;
        for (int z = 0; z < 2; z++) {
            cin >> m[z];
//            int lft = 50'000 - (n - 1);
//            m[z] = 50'000;//(n - 1) + (rnd() % (lft + 1));
            /*while (2 * m[z] > (1LL * n * (n - 1))) {
                m[z] = (n - 1) + (rnd() % (lft + 1));
            }
            set<pair<int,int>> s;
            for (int j = 0; j < n - 1; j++) {
                int Y = j + 2;
                int X = (rnd() % (j + 1)) + 1;
                s.insert(minmax(X, Y));
                a[z][j] = X;
                b[z][j] = Y;
            }
            for (int j = n - 1; j < m[z]; j++) {
                while (true) {
                    int X = rnd() % n + 1;
                    int Y = rnd() % n + 1;
                    if (X == Y) continue;
                    if (X > Y) continue;
                    if (s.count({X, Y})) {
                        continue;
                    }
                    s.insert(minmax(X, Y));
                    a[z][j] = X;
                    b[z][j] = Y;
                    break;
                }
            }*/
            for (int j = 0; j < m[z]; j++) {
                cin >> a[z][j] >> b[z][j];
            }
        }
        auto t1 = go(0);
        auto t2 = go(1);
        vector<pair<int, int>> s;
        reverse(t2.begin(), t2.end());
        for (auto &it: t2) {
            it.first = ~it.first;
            it.second = ~it.second;
            t1.emplace_back(it);
        }
        assert((int) t1.size() <= 200'000);
        /*set<pair<int,int>> X;
        for (int i = 0; i < m[0]; i++) {
            X.insert(minmax(a[0][i], b[0][i]));
        }
        auto upd = [&](int a, int b) {
            if (a < 0) {
                a = ~a;
                b = ~b;
                assert(X.count(minmax(a, b)));
                bool hs = false;
                for (int c = 1; c <= n; c++) {
                    if (X.count(minmax(c, a)) && X.count(minmax(c, b))) hs = true;
                }
                assert(hs);
                X.erase(minmax(a, b));
            }
            else {
                assert(!X.count(minmax(a, b)));
                bool hs = false;
                for (int c = 1; c <= n; c++) {
                    if (X.count(minmax(c, a)) && X.count(minmax(c, b))) hs = true;
                }
                assert(hs);
                X.insert(minmax(a, b));
            }
        };*/
        cout << t1.size() << '\n';
        for (auto &it: t1) {
//            upd(it.first, it.second);
            if (it.first < 0) {
                cout << "- " << ~it.first << " " << ~it.second << '\n';
            } else {
                cout << "+ " << it.first << " " << it.second << '\n';
            }
        }
        return 0;
    }
    return 0;
}