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
#include <iostream>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;

struct czyn
{
    char t;
    int a, b;
    czyn(char c, int a1, int b1)
    {
        t = c;
        a = a1;
        b = b1;
    }
};

const ll maxN = 3e5+3;
int n, m;
set<int> pol[maxN];
set<int> pol_[maxN];
int vis[maxN];
queue<czyn> r;

void DFS(int x, int cel)
{
    vis[x] = true;
    if (x != cel && pol[x].find(cel) == pol[x].end())
    {
        r.push({'+', x, cel});
        pol[x].insert(cel);
        pol[cel].insert(x);
    }
    for (auto v : pol[x])
    {
        if (!vis[v])
        {
            DFS(v, cel);
        }
    }
    return;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        pol[a].insert(b);
        pol[b].insert(a);
    }
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        pol_[a].insert(b);
        pol_[b].insert(a);
    }
    vis[1] = true;
    DFS(1, 1);
    for (int i = 1; i <= n; i++)
    {
        for (auto v : pol_[i])
        {
            if (pol[i].find(v) == pol[i].end())
            {
                r.push({'+', i, v});
                pol[i].insert(v);
                pol[v].insert(i);
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (auto v : pol[i])
        {
            if (pol_[i].find(v) == pol_[i].end())
            {

                r.push({'-', i, v});
                pol[v].erase(i);
            }
        }
    }

    cout << r.size() << "\n";
    while (!r.empty())
    {
        cout << r.front().t << " "  << r.front().a << " "  << r.front().b << "\n";
        r.pop();
    }
    return 0;
}