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
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif

#define x first
#define y second
#define ir(a, x, b) ((a) <= (x) && (x) <= (b))
#define vec vector
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(), (x).end()

using ll = long long;
int n;

vec<bool> conn, vis;
vec<pair<bool, pair<int, int>>> ops, ops2;
vec<pair<int, int>> edges;
vec<vec<int>> g;

void add(int a, int b) {
    ops.push_back({true, {a, b}});
}

void rem(int a, int b) {
    ops.push_back({false, {a, b}});
}

void dfs(int v, int p, int omit) {
    if (vis[v]) return;
    vis[v] = true;
    if (omit <= 0 && !conn[v]) {
        add(0, v);
    }
    for (auto c : g[v]) {
        if (c == p) continue;
        dfs(c, v, omit-1);
    }
}

void solve() {
    int m;
    cin >> m;
    conn.assign(n, 0);
    edges.clear();
    edges.reserve(m);
    g.assign(n, {});
    vis.assign(n, false);
    rep (i, 0, m) {
        int a, b; cin >> a >> b; --a, --b;
        g[a].push_back(b); g[b].push_back(a);
        if (a == 0) conn[b] = true;
        if (b == 0) conn[a] = true;
        edges.push_back({a, b});
    }
    dfs(0, 0, 2);
    for (auto [a, b] : edges) {
        if (a != 0 && b != 0) {
            rem(a, b);
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    solve();
    swap(ops, ops2);
    solve();
    swap(ops, ops2);
    cout << ops.size() + ops2.size() << "\n";
    for (auto [op, e] : ops) {
        auto [a, b] = e;
        cout << (op?'+':'-') << " " << a+1 << " " << b+1 << "\n";
    }
    reverse(all(ops2));
    for (auto [op, e] : ops2) {
        auto [a, b] = e;
        cout << (op?'-':'+') << " " << a+1 << " " << b+1 << "\n";
    }
    return 0;
}