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
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=3e4+5;
int n,m;
vector<int>G[N],H[N];
int vs[N],vt[N],vx[N];
vector<tuple<char,int,int>>ans;
inline void dfs(int u){
    vx[u]=1;
    for(auto v:H[u])if(!vx[v])dfs(v);
    if(!vt[u])ans.emplace_back('-',1,u);
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>m;
    for(int i=1;i<=m;++i){
        int u,v;cin>>u>>v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    queue<int>Q;
    Q.emplace(1),vs[1]=1;
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        for(auto v:G[u])if(!vs[v]){
            Q.emplace(v),vs[v]=1;
            if(u!=1)ans.emplace_back('+',1,v);
        }
    }
    for(int u=2;u<=n;++u)
        for(auto v:G[u])if(u<v)ans.emplace_back('-',u,v);
    cin>>m;
    for(int i=1;i<=m;++i){
        int u,v;cin>>u>>v;
        H[u].emplace_back(v);
        H[v].emplace_back(u);
        if(u!=1&&v!=1)ans.emplace_back('+',u,v);
        else vt[u^v^1]=1;
    }
    vt[1]=1,dfs(1);
    cout<<ans.size()<<'\n';
    for(auto [x,y,z]:ans)cout<<x<<' '<<y<<' '<<z<<'\n';
    return 0;
}
/*

*/