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

vector<int> v[30001];
bool c[30001];

vector<int> funkcja() {
	vector<int> ans;
	for(int i=0; i<30001; ++i) c[i] = false;
	queue<int> q;
	q.push(1);
	c[1] = true;
	for(int i=0; i<v[1].size(); ++i) {
		q.push(v[1][i]);
		c[v[1][i]] = true;
	}
	q.pop();
	while(!q.empty()) {
		int nr;
		nr = q.front();
		q.pop();
		for(int i=0; i<v[nr].size(); ++i) {
			int p = v[nr][i];
			if(c[p] == false) {
				c[p] = true;
				q.push(p);
				ans.push_back(p);
			}
		}
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	int N,M,a[30001],b[30001];
	cin>>N;
	cin>>M;
	for(int i=0; i<M; ++i) {
		cin>>a[i]>>b[i];
		v[a[i]].push_back(b[i]);
		v[b[i]].push_back(a[i]);
	}
	vector<int> k;
	k = funkcja();
	vector< pair<int,int> > p;
	for(int i=0; i<M; ++i) {
		if(a[i] != 1 && b[i] != 1) p.push_back(make_pair(a[i],b[i]));
	}
	for(int i=0; i<30001; ++i) v[i].clear();
	vector< pair<int,int> > r;
	cin>>M;
	for(int i=0; i<M; ++i) {
		cin>>a[i]>>b[i];
		v[a[i]].push_back(b[i]);
		v[b[i]].push_back(a[i]);
		if(a[i] != 1 && b[i] != 1) r.push_back(make_pair(a[i],b[i]));
	}
	vector<int> m;
	m = funkcja();
	cout<<k.size()+p.size()+r.size()+m.size()<<endl;
	for(int i=0; i<k.size(); ++i) cout<<"+ 1 "<<k[i]<<endl;
	for(int i=0; i<p.size(); ++i) cout<<"- "<<p[i].first<<" "<<p[i].second<<endl;
	for(int i=0; i<r.size(); ++i) cout<<"+ "<<r[i].first<<" "<<r[i].second<<endl;
	for(int i=m.size(); i>=1; --i) cout<<"- 1 "<<m[i-1]<<endl;
	
	
	return 0;
}