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

struct Event{
    char t;
    int a;
    int b;
};

vector<Event> res;
void to_star(int n, bool rev){
    int m;
    cin>>m;
    vector<vector<int>> G(n+1, vector<int>());
    for(int i=0;i<m;i++){
        int a, b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist(n+1, -1);
    vector<Event> tmp;
    dist[1] = 0;
    queue<int> Q;
    Q.push(1);
    while(!Q.empty()){
        int v = Q.front();
        Q.pop();
        for(int u: G[v]){
            if(dist[u] == -1){
                dist[u] = dist[v]+1;
                Q.push(u);
                if(dist[u] > 1){
                    tmp.push_back({'+', 1, u});
                }
            }
        }
    }

    for(int i=2;i<=n;i++){
        for(int u: G[i]){
            if(u > 1 && u < i){
                tmp.push_back({'-', u, i});
            }
        }
    }

    if(!rev){
        for(Event e: tmp) res.push_back(e);
    }
    else{
        reverse(tmp.begin(), tmp.end());
        for(Event e: tmp){
            if(e.t == '+') e.t = '-';
            else e.t = '+';
            res.push_back(e);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    to_star(n, false);
    to_star(n, true);

    cout<<res.size()<<endl;
    for(Event e: res){
        cout<<e.t<<" "<<e.a<<" "<<e.b<<endl;
    }
}