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
#include <iostream>
#include <vector>
#include <map>
using namespace std;

map< pair<int,int> , int> ist;

vector<int> tab[50'007];

vector< pair<char,pair<int,int> > > ruchy;

int byo[50'007];

void gwi(int v)
{
    if(byo[v]!=0)
        return;
    byo[v]=1;
    if(ist[{1,v}]==0 && 1!=v)
        ruchy.push_back({'+',{1,v}});// cout<<"+ "<<1<<" "<<v<<"\n";
    for(int a=0; a<tab[v].size(); a++)
        gwi(tab[v][a]);
}

void roz(int v)
{
    if(byo[v]!=0)
        return;
    byo[v]=1;
    for(int a=0; a<tab[v].size(); a++)
        roz(tab[v][a]);
    if(ist[{1,v}]==0 && v!=1)
        ruchy.push_back({'-',{1,v}});//cout<<"- "<<1<<" "<<v<<"\n";
}

int main()
{
    int n, m, p, p2;
    cin>>n;
    cin>>m;
    for(int a=0; a<m; a++)
    {
        cin>>p>>p2;
        if(p>p2)
            swap(p,p2);
        tab[p].push_back(p2);
        tab[p2].push_back(p);
        ist[{p,p2}]++;
    }
    gwi(1);
    for(auto it=ist.begin(); it!=ist.end(); it++){
        if((it->second)!=0 && (it->first).first!=1 && (it->first).second!=1)
            ruchy.push_back({'-',{((it->first).first),((it->first).second)}});//cout<<"-"<<(it->first).first<<" "<<(it->first).second<<"\n";
    }

    for(int a=1; a<=n; a++)
        tab[a].clear();
    ist.clear();
    for(int a=0; a<=n; a++)
        byo[a]=0;

    cin>>m;
    for(int a=0; a<m; a++)
    {
        cin>>p>>p2;
        if(p>p2)
            swap(p,p2);
        tab[p].push_back(p2);
        tab[p2].push_back(p);
        ist[{p,p2}]++;
        if(p!=1 && p2!=1)
            ruchy.push_back({'+',{p,p2}});//cout<<"+ "<<p<<" "<<p2<<"\n";
    }
    roz(1);
    cout<<ruchy.size()<<"\n";
    for(int a=0; a<ruchy.size(); a++)
        cout<<ruchy[a].first<<" "<<ruchy[a].second.first<<" "<<ruchy[a].second.second<<"\n";
}