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
// clang-format off
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ssize(x) int(x.size())
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<typename T,typename = typename enable_if<!is_same<T,string>::value>::type>
auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
// clang-format on

bitset<30007> graph1;
bitset<30007> graph2;
vector<int> vgraph1[30007];
vector<int> vgraph2[30007];
vector<pair<char, pair<int, int>>> ans;
vector<pair<int, int>> edges1;
vector<pair<int, int>> edges2;

bitset<30007> vis;
void dfs1(int v)
{
    vis[v] = 1;
    for (int u : vgraph1[v])
    {
        if (vis[u])
            continue;
        if (!graph1[u])
        {
            ans.push_back({'+', {1, u}});
        }
        dfs1(u);
    }
}

void dfs2(int v)
{
    vis[v] = 1;
    for (int u : vgraph2[v])
    {
        if (vis[u])
            continue;
        dfs2(u);
        if (!graph2[u])
        {
            ans.push_back({'-', {1, u}});
        }
    }
}

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

    int n, m1, m2, a, b;
    cin >> n;
    cin >> m1;
    for (int i = 0; i < m1; i++)
    {
        cin >> a >> b;
        if (b < a)
            swap(a, b);
        if (a == 1)
            graph1[b] = 1;
        vgraph1[a].push_back(b);
        vgraph1[b].push_back(a);
        edges1.push_back({a, b});
    }
    cin >> m2;
    for (int i = 0; i < m2; i++)
    {
        cin >> a >> b;
        if (b < a)
            swap(a, b);
        if (a == 1)
            graph2[b] = 1;
        vgraph2[a].push_back(b);
        vgraph2[b].push_back(a);
        edges2.push_back({a, b});
    }
    dfs1(1);
    vis.reset();
    for (auto i : edges1)
        if (i.first != 1)
            ans.push_back({'-', i});

    for (auto i : edges2)
        if (i.first != 1)
            ans.push_back({'+', i});

    dfs2(1);
    cout << ssize(ans) << '\n';
    for (auto i : ans)
        cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';

    return 0;
}