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
#include<iostream>
#include<vector>
#include<set>
#include<iterator>
#include<queue>
std::vector<std::set<int> > v(30005),v2(30005);
int main()
{
	int n, k, a, b;
	std::ios_base::sync_with_stdio(false);
	std::queue<int>q,q2;
	std::cin.tie(0);
	std::cout.tie(0);
	std::cin >> n >> k;
	for (int i = 0; i < k; i++) {
		std::cin >> a >> b;
		v[a].insert(b);
		v[b].insert(a);
	}
	std::cin >> k;

	for (int i = 0; i < k; i++) {
		std::cin >> a >> b;
		v2[a].insert(b);
		v2[b].insert(a);
		if (v[a].find(b) == v[a].end()) {
			int p = *v[a].begin();
			if (v[b].find(p) != v[b].end()) {
				continue;
			}
			else {
			//	std::cout << "+ " << b << " " << p << '\n';
				//std::cout << "+ " << a << " " << b << '\n';
				q.push(b);
				q.push(p);
				q.push(a);
				q.push(b);
				v[b].insert(p);
				v[p].insert(b);
			}
		}
		else {
			continue;
		}
	}
	std::set<int>::iterator it;
	for (int i = 1; i <= n; i++) {
		for (it = v[i].begin(); it != v[i].end(); it++) {
			if (v2[i].find(*it) == v2[i].end()) {
			//	std::cout << "- " << i << " " << *it << '\n';
				q2.push(i);
				q2.push(*it);
				v[*it].erase(i);
			}
		}
	}
	std::cout << (q.size() + q2.size())/2 << '\n';
	while (!q.empty()) {
		std::cout << "+ " << q.front() << " ";
		q.pop();
		std::cout << q.front()<<'\n';
		q.pop();
	}
	while (!q2.empty()) {
		std::cout << "- " << q2.front() << " ";
		q2.pop();
		std::cout << q2.front() << '\n';
		q2.pop();
	}
}