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
#include <bits/stdc++.h>
using namespace std;
int n,ma,mb,a,b;
struct tre
{
    char a;
    int b,c;
};
vector <int> v[30005];
vector <int> w[30005];
vector <pair<int,int> > pv;
vector <pair<int,int> > pw;
vector <tre> wyn;
vector <bool> odw;
vector <bool> con;
void ca(int x)
{
    odw[x]=true;
    if(!con[x])wyn.push_back({'+',1,x});
    for(int i=0;i<(int)v[x].size();i++)
    {
        int d=v[x][i];
        if(!odw[d])ca(d);
    }
    return;
}
void dca(int x)
{
    odw[x]=false;
    for(int i=0;i<(int)w[x].size();i++)
    {
        int d=w[x][i];
        if(odw[d])dca(d);
    }
    if(!con[x])wyn.push_back({'-',1,x});
    return;
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin>>n>>ma;
    for(int i=0;i<ma;i++)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
        pv.push_back({a,b});
    }
    cin>>mb;
    for(int i=0;i<mb;i++)
    {
        cin>>a>>b;
        w[a].push_back(b);
        w[b].push_back(a);
        pw.push_back({a,b});
    }
    con.resize(n+3,false);
    con[1]=true;
    for(int i=0;i<(int)v[1].size();i++)
    {
        con[v[1][i]]=true;
    }
    odw.resize(n+3,false);
    ca(1);
    con.resize(0);
    con.resize(n+3,false);
    for(auto [x,y]:pv)
    {
        if(x!=1&&y!=1)wyn.push_back({'-',x,y});
    }
    for(auto [x,y]:pw)
    {
        if(x!=1&&y!=1)wyn.push_back({'+',x,y});
        else if(x==1)
        {
            swap(x,y);
            con[x]=true;
        }
    }
    con[1]=true;
    dca(1);
    cout<<wyn.size()<<endl;
    for(auto [x,y,z]:wyn)
    {
        cout<<x<<" "<<y<<" "<<z<<endl;
    }
    return 0;
}