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

vector<int> g[30001];
set<pair<int, int>> edges;

vector<pair<bool, pair<int, int>>> ans;

int n, m;
int a, b;

bool vis[30001];
void dfs1(int v){
    vis[v] = true;

    if(v > 1 && !edges.count({1, v})){
        ans.push_back({true, {1, v}});
        edges.insert({1, v});
    }

    for(auto u : g[v]){
        if(!vis[u]){
            dfs1(u);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        if(a > b) swap(a, b);
        g[a].push_back(b);
        g[b].push_back(a);
        edges.insert({a, b});
    }

    dfs1(1);

    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        if(a > b) swap(a, b);
        if(edges.count({a, b})){
            edges.erase({a, b});
        }
        else{
            ans.push_back({true, {a, b}});
        }
    }

    for(auto e : edges){
        ans.push_back({false, e});
    }

    cout << ans.size() << "\n";
    for(auto e : ans){
        if(e.first){
            cout << "+ " << e.second.first << " " << e.second.second << "\n";
        }
        else{
            cout << "- " << e.second.first << " " << e.second.second << "\n";
        }
    }
}