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
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b;
bool odw[30007];
set<pair<int,int>>baj;
vector<pair<char,pair<int,int>>>v;
vector<int>graf[30007];
void DFS(int w,int wierz){
	odw[w]=true;
	for(int i=0; i<graf[w].size();i++){
		int next=graf[w][i];
		if(!odw[next]){
        if(!baj.count({min(wierz,next),max(wierz,next)})){
           v.push_back({'+',{wierz,next}});
            baj.insert({min(wierz,next),max(wierz,next)});
		}
			DFS(next,wierz);
		}
	}
return;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
cin>>n>>m;

for(int i=0;i<m;i++){
    cin>>a>>b;
    baj.insert({min(a,b),max(a,b)});
    graf[a].push_back(b);
    graf[b].push_back(a);
}
int wierz=0,maks=0;
for(int i=1;i<=n;i++){
    if(graf[i].size()>maks){
    maks=graf[i].size();
    wierz=i;}
}
DFS(wierz,wierz);
set<pair<int,int>>ost;
cin>>m;
for(int i=0;i<m;i++){
    cin>>a>>b;
    ost.insert({min(a,b),max(a,b)});
}
for(pair<int,int>akt:ost){
    if(!baj.count(akt)){
        v.push_back({'+',akt});
    }
}
for(pair<int,int>akt:baj){
    if(!ost.count(akt)){
        v.push_back({'-',akt});
    }
}
cout<<v.size()<<"\n";
for(pair<char,pair<int,int>>a:v){
    cout<<a.first<<" "<<a.second.first<<" "<<a.second.second<<"\n";
}
return 0;}